By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

split or regex difference between FF and IE

P: n/a
I don't know where the actual issue is,
but hopefully someone can explain.

The following displays "5" in FireFox, but "3" in IE:

<script type="text/javascript" language="javascript">
var newString = ",a,b,c,";
var treeArray = newString.split(/\,/i);
alert(treeArray.length);

</script>

Thanks,
Jim

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<jh*****@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I don't know where the actual issue is,
but hopefully someone can explain.

The following displays "5" in FireFox, but "3" in IE:

<script type="text/javascript" language="javascript">
var newString = ",a,b,c,";
var treeArray = newString.split(/\,/i);
alert(treeArray.length);

</script>

Thanks,
Jim


You've found one of the known issues with the String#split() method and
IE.

When you call split() using a String as the argument, IE includes empty
items in the resulting Array.

When you call split() using a RegExp as the argument, IE drops empty
items in the resulting Array.

var s = 'a#b##c###d';

// "4" - all Array elements contain non-empty strings
alert(s.split(/#/).length);

// "7" - Array elements 2, 4 and 5 are empty strings
alert(s.split("#").length);

Note that in Gecko-based browsers and Opera, both alert "7". So the
simplest solution is probably to use String#split() with a String as the
parameter instead of a RegExp.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.