473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

split or regex difference between FF and IE

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
1 2871
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chris | last post by:
hello, I have question about the re.I option for Regular Expressions: >>> import re >>> re.findall('x', '1x2X3', re.I) as expected finds both lower and uppercase x
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
5
by: lgbjr | last post by:
Hello All, I have the following type of string: "X:Y\Z.exe" "123" What I need is an array of strings with the information from within each set of quotes. I was trying to use a Regex.Split, but...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
7
by: Jordi Rico | last post by:
Hi, I know I can split a string into an array doing this: Dim s As String()=Regex.Split("One-Two-Three","-") So I would have: s(0)="One" s(1)="Two"
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
12
blazedaces
by: blazedaces | last post by:
Hello again. I'm trying to take as an input an ArrayList<String> and utilize String's .spit(delimiter) method to turn that into a String. I'm getting some kind of error though (I'll post the code...
1
by: mad.scientist.jr | last post by:
I am working in C# ASP.NET framework 1.1 and for some reason Regex.Split isn't working as expected. When trying to split a string, Split is returning an array with the entire string in element ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.