PDA

View Full Version : how to split string with non equal separator


umen
01-03-2003, 06:44 AM
Hello
im looking for fast and clean way (avoiding looping throw the string)
to split string in this struct :
"blah1 blah2 blah3 blah4 blah5"
as you can see there spaces between the blah's is not equal and i need only the blah's
what do you think will be the best way to separate them?
(i was of curse thinking about looping the string and and checking when space is staring and ending )
thanks

umen
01-03-2003, 07:01 AM
i just saw that the forum is ignoring more then 1 space between word , so just imagine there is
none equal space between the blah's

whammy
01-03-2003, 11:25 PM
<script type="text/javascript">
<!--
function splitOnSpaces(str) {
return str.split(/\s+/);
}
// -->
</script>

<form id="blah" action="javascript://">
<input type="text" name="mystring" onblur="this.value=splitOnSpaces(this.value)" />
</form>


:)

P.S. If you wanted to join them back together with one space in between:

return str.split(/\s+/).join(' ');