parsing difference between Netscape and IE.

  • Thread starter Better but still clumpsy
  • Start date
B

Better but still clumpsy

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.
 
R

RobG

Better said:
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
 
R

rh

Better said:
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
 
B

Better but still clumpsy

Yes, I made a mistake(typo). Actually, item was fetched from a combo
box like this.
item=kpgn_list.options.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 said:
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
 
B

Better but still clumpsy

Hi RobG,

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

item=kpgn_list.options.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 said:
Better said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top