469,306 Members | 2,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

parsing difference between Netscape and IE.


I have the three following scripts.

var pat_piece=/(\w{2})-(\w{2,3})/;
item=="kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]
var piece=item.split(pat_piece);

Netscape is able to split it correctly while IE isn't. What should
pat_piece look like if I only want item to be splitted any word
like WN-a10 to two?

Thanks.
Jul 23 '05 #1
5 1331
Better but still clumpsy wrote:
I have the three following scripts.

var pat_piece=/(\w{2})-(\w{2,3})/;
item=="kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]
var piece=item.split(pat_piece);

Netscape is able to split it correctly while IE isn't. What should
What do you mean by "split it correctly"? It doesn't work at
all in any browser I tried it in.
pat_piece look like if I only want item to be splitted any word
like WN-a10 to two?


If you want to split only on the '-', then split on it:

var item = "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1";
var piece = item.split('-');

'piece' will be an array where:

piece[0] = "WN"
piece[1] = "a10 WR"
piece[2] = "a11 WP"
...
piece[6] = "f1"

If you want to split on the spaces also, either replace one or
more spaces with '-' then split on the '-', or split on either
'-' or '\s+':

var piece = item.split(/-|\s+/)

now 'piece' will be an array where:

piece[0] = "WN"
piece[1] = "a10"
piece[2] = "WR"
...
piece[11] = "f1"

the pattern \s+ will match one or more white space characters,
which is any of \f \n \r \t \v \u00A0 \u2028 \u2029

--
Rob
Jul 23 '05 #2
rh
Better but still clumpsy wrote:
I have the three following scripts.

var pat_piece=/(\w{2})-(\w{2,3})/;
item=="kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]
var piece=item.split(pat_piece);

Netscape is able to split it correctly while IE isn't. What should
pat_piece look like if I only want item to be splitted any word
like WN-a10 to two?


There are a number of problems here.

For starters, the sample code you have given is incorrect. Since
"split" works on strings, it would seem that you meant item to be
assigned a string, and perhaps that was supposed to read:

item = '"kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]';

Then on to the difficulties with IE. Rather unfortunately "window.item"
seems to be some sort of pre-defined property in IE, and it cannot be
overridden unless it is prefixed with "var " (go figure :~/). So

var item = '"kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]';

allows the assignment (but it might be prudent to choose a different
identifier).

Next, IE doesn't split the string in accordance with the ECMA 263/3
standard, as it appears not to do the splicing of captured values back
into the string segments as it performs the split.

If the given pattern is required to effect the split, your best
alternative is likely to pre-condition the string prior to splitting,
e.g.,

var piece = item.replace(pat_piece, "$1#$2").split("#");

../rh

Jul 23 '05 #3
rh

rh wrote:

var piece = item.replace(pat_piece, "$1#$2").split("#");


And of course pat_piece will also need a "g" modifier added.

../rh

Jul 23 '05 #4
"rh" <co********@yahoo.ca> writes:

Yes, I made a mistake(typo). Actually, item was fetched from a combo
box like this.
item=kpgn_list.options[i].text; and item was declared at the
beginning of the function.

After it split, I call three function to get the piece, x and y
coordinate for displaying the table.

Thanks.
Better but still clumpsy wrote:
I have the three following scripts.

var pat_piece=/(\w{2})-(\w{2,3})/;
item=="kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]
var piece=item.split(pat_piece);

Netscape is able to split it correctly while IE isn't. What should
pat_piece look like if I only want item to be splitted any word
like WN-a10 to two?


There are a number of problems here.

For starters, the sample code you have given is incorrect. Since
"split" works on strings, it would seem that you meant item to be
assigned a string, and perhaps that was supposed to read:

item = '"kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]';

Then on to the difficulties with IE. Rather unfortunately "window.item"
seems to be some sort of pre-defined property in IE, and it cannot be
overridden unless it is prefixed with "var " (go figure :~/). So

var item = '"kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]';

allows the assignment (but it might be prudent to choose a different
identifier).

Next, IE doesn't split the string in accordance with the ECMA 263/3
standard, as it appears not to do the splicing of captured values back
into the string segments as it performs the split.

If the given pattern is required to effect the split, your best
alternative is likely to pre-condition the string prior to splitting,
e.g.,

var piece = item.replace(pat_piece, "$1#$2").split("#");

../rh

Jul 23 '05 #5
Hi RobG,

Well, I made a mistake(typo). Actually, item was fetched from
a combo box like this.

item=kpgn_list.options[i].text;

Of coourse, it work on Netscape/Modzilla. What I mean by split
correctly, the data in the piece array have :
piece[.] = "WN"
piece[.+1] = "a10"
piece[.+2] = "WR"
piece[.+3] = "a11"
and IE gave me only
Setup and the rest of array blank.

Anyway, I am using just /-/ and all browsers are splitting the same
and I had modified the function to accomodate this splitting array.
The program is working on all three browsers now.
My only task left is to size the combo box so that it will look
the same on any browser. Right now, it uses default size and IE
gave me only three lines of item while Netscape gave me just
about the right size that is fitted in its parent frame.
If you want too, you can take a look at it.

http://71.96.69.35

PS. Since, Verizon is no longer give me a fix IP address, this
URL might not be valid if my network/computer is rebooted.

Thanks for all your help.
RobG <rg***@iinet.net.auau> writes:
Better but still clumpsy wrote:
I have the three following scripts.
var pat_piece=/(\w{2})-(\w{2,3})/;
item=="kpgn9">[Setup "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1"]
var piece=item.split(pat_piece);
Netscape is able to split it correctly while IE isn't. What should


What do you mean by "split it correctly"? It doesn't work at
all in any browser I tried it in.
pat_piece look like if I only want item to be splitted any word
like WN-a10 to two?


If you want to split only on the '-', then split on it:

var item = "WN-a10 WR-a11 WP-c5 SR-d1 SN-e1 SB-f1";
var piece = item.split('-');

'piece' will be an array where:

piece[0] = "WN"
piece[1] = "a10 WR"
piece[2] = "a11 WP"
...
piece[6] = "f1"

If you want to split on the spaces also, either replace one or
more spaces with '-' then split on the '-', or split on either
'-' or '\s+':

var piece = item.split(/-|\s+/)

now 'piece' will be an array where:

piece[0] = "WN"
piece[1] = "a10"
piece[2] = "WR"
...
piece[11] = "f1"

the pattern \s+ will match one or more white space characters,
which is any of \f \n \r \t \v \u00A0 \u2028 \u2029

--
Rob

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Max Skaller | last post: by
2 posts views Thread by Michele Simionato | last post: by
1 post views Thread by cmika | last post: by
16 posts views Thread by Ben | last post: by
4 posts views Thread by Guru | last post: by
3 posts views Thread by Sanjay Arora | last post: by
reply views Thread by =?Utf-8?B?VWxmIFRob3JzZW4=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.