JRS: In article <
[email protected]>, seen in
news:comp.lang.javascript said:
Dr John Stockton said:
JRS: In article <
[email protected]>, seen
in aliensite <
[email protected]> posted at
Mon, 16 Feb 2004 11:54:46 :-
I think you forgot the +, i.e.,
A = S.split(/[^0-9\.]+/)
Otherwise "3, 4" will be split into three parts, the middle one empty.
I tested it, without +, on the OP's strings, and noticed no empty
element.
OTOH you are obviously right.
OTTH, in my MSIE4,
A = "3, 4".split(/[^0-9\.]/)
returns [3,4] of .length 2.
A saved Netscape page implies that .split was different (from what?) in
JS1.2 -
<QUOTE>
Example 2. Consider the following script:
<SCRIPT LANGUAGE="JavaScript1.2">
str="She sells seashells \nby the\n seashore"
document.write(str + "<BR>")
a=str.split(" ")
document.write(a)
</SCRIPT>
Using LANGUAGE="JavaScript1.2", this script produces
"She", "sells", "seashells", "by", "the", "seashore"
Without LANGUAGE="JavaScript1.2", this script splits only on single
space characters, producing
"She", "sells", , , , "seashells", "by", , , "the", "seashore"
</QUOTE>
ECMA 262 explains .split in impenetrable detail.
OP: Use the +.