Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CSV and regex s.split(",") and empty fields

55 views
Skip to first unread message

Gerry Hickman

unread,
Aug 28, 2009, 10:13:36 AM8/28/09
to
Hi,

I can use s.split(",") to split a CSV file into fields when the file looks
like this

one, two, three

BUT, in real life, my input file looks like this

one, two,,four,,,seven,eight

Note that some fields are empty. When I try to use s.split(",") it ignores
the empty fields and my array ends up with only five elements instead of
eight. I would like to end up with an eight element array where some fields
contain an empty string.

If it can't be done with s.split(), is there a function that would do this?

Thanks.

--
Gerry Hickman
London (UK)

Evertjan.

unread,
Aug 28, 2009, 10:45:03 AM8/28/09
to
Gerry Hickman wrote on 28 aug 2009 in
microsoft.public.scripting.jscript:

> I can use s.split(",") to split a CSV file into fields when the file
> looks like this
>
> one, two, three
>
> BUT, in real life, my input file looks like this
>
> one, two,,four,,,seven,eight
>
> Note that some fields are empty. When I try to use s.split(",") it
> ignores the empty fields and my array ends up with only five elements
> instead of eight. I would like to end up with an eight element array
> where some fields contain an empty string.
>

Not true!

<script type='text/javascript'>
var t = 'one,two,,four,,,seven,eight';
var n = t.split(',').length;
alert(n);
</script>

returns 8.

using regex:

var n = t.split(/,/).length;

also returns 8.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Gerry Hickman

unread,
Aug 28, 2009, 4:16:00 PM8/28/09
to
Hello,

Sorry, I didn't test properly, and made a mess of the original post. I
should have explained I'm running under WSH, not in a browser. Either
way, when using a string delimiter, it appears to work!

However, when using regex, I don't see the same results you posted
below. Here's the example code - run under cscript

// cscript split.js
// Split string
var t = 'one,two,,four,,,seven,eight';
var a = t.split(",");
var n = a.length;
WScript.Echo(n); // prints 8
var a = t.split(/,/);
var n = a.length;
WScript.Echo(n); // prints 5

Do you get the same results?


--
Gerry Hickman (London UK)

Evertjan.

unread,
Aug 28, 2009, 6:43:04 PM8/28/09
to
Gerry Hickman wrote on 28 aug 2009 in microsoft.public.scripting.jscript:

[Please do not toppost on usenet]

> Sorry, I didn't test properly, and made a mess of the original post. I
> should have explained I'm running under WSH, not in a browser. Either
> way, when using a string delimiter, it appears to work!
>
> However, when using regex, I don't see the same results you posted
> below. Here's the example code - run under cscript
>
> // cscript split.js
> // Split string
> var t = 'one,two,,four,,,seven,eight';
> var a = t.split(",");
> var n = a.length;
> WScript.Echo(n); // prints 8
> var a = t.split(/,/);
> var n = a.length;
> WScript.Echo(n); // prints 5
>
> Do you get the same results?

yes:

var n = t.split(/,/).length;

cscript and IE8 return 5

FF and Chrome return 8


So definitly a serious error in the M$ jscript engine.

Gerry Hickman

unread,
Aug 29, 2009, 12:51:30 PM8/29/09
to

Evertjan. wrote:

> var n = t.split(/,/).length;
>
> cscript and IE8 return 5
>
> FF and Chrome return 8

> So definitly a serious error in the M$ jscript engine.

OK, is there a way to create a new split() function that would accept a
RegEx and work correctly?

Evertjan.

unread,
Aug 29, 2009, 2:37:51 PM8/29/09
to
Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.jscript:

>
> Evertjan. wrote:
>
>> var n = t.split(/,/).length;
>>
>> cscript and IE8 return 5
>>
>> FF and Chrome return 8
>
>> So definitly a serious error in the M$ jscript engine.
>
> OK, is there a way to create a new split() function that would accept a
> RegEx and work correctly?

What do you think?
and what did you try?
and why do you need the regex version?

I think there is.

Gerry Hickman

unread,
Aug 29, 2009, 2:48:50 PM8/29/09
to
Evertjan. wrote:

>> OK, is there a way to create a new split() function that would accept a
>> RegEx and work correctly?
>
> What do you think?
> and what did you try?
> and why do you need the regex version?
>
> I think there is.

I'd like to design a new one, but need some help to do it.

One other possible workaround would be to hack the regex in order to
"trick" the split method into working correctly. The closest thing I've
found so far is this:

var t = 'one,two,,four,,,seven,eight';
var a = t.split(/(?=,)/);


var n = a.length;
WScript.Echo(n); // prints 8

but you end up with this (note leading commas)

one
,two
,
,four
,
,
,seven
,eight

I need to get the regex version working, because in real life the string
version will only cope with very simple delimiter arrangements.

Thanks.

Evertjan.

unread,
Aug 29, 2009, 3:09:55 PM8/29/09
to
Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.jscript:

> I need to get the regex version working, because in real life the string
> version will only cope with very simple delimiter arrangements.
>

var a = t.replace(/,/g,'$comma$').split('$comma$');

Dr J R Stockton

unread,
Aug 29, 2009, 4:44:05 PM8/29/09
to
In microsoft.public.scripting.jscript message <#ZO38m#JKHA...@TK2MSFTNGP03.ph
x.gbl>, Fri, 28 Aug 2009 15:13:36, Gerry Hickman
<gerry...@newsgroup.nospam> posted:


NOW there is.

t = 'one,two,,four,,,seven,eight';

String.prototype.Split = function() {
var A = [], S= "", J
for (J=0 ; J<this.length ; J++) {
if (this.charAt(J)==",") { A.push(S) ; S = "" } else S += this.charAt(J) }
if (S>"") A.push(S)
return A }

X = t.Split().join("+") // one+two++four+++seven+eight

You might check what happens id the first or last character is a comma.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Evertjan.

unread,
Aug 30, 2009, 6:28:07 AM8/30/09
to
Dr J R Stockton wrote on 29 aug 2009 in
microsoft.public.scripting.jscript:

> NOW there is.


>
> t = 'one,two,,four,,,seven,eight';
>
> String.prototype.Split = function() {
> var A = [], S= "", J
> for (J=0 ; J<this.length ; J++) {
> if (this.charAt(J)==",") { A.push(S) ; S = "" } else S +=
> this.charAt(J) }
> if (S>"") A.push(S)
> return A }
>
> X = t.Split().join("+") // one+two++four+++seven+eight

This does not help, John,
as the split(',') is working.

It is the split(/,/) that is buggy
in IE and w/cscript.

The OP stipulated that he needed complex regex split in cscript.

Gerry Hickman

unread,
Aug 30, 2009, 7:25:09 AM8/30/09
to
Evertjan. wrote:
> Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.jscript:
>
>> I need to get the regex version working, because in real life the string
>> version will only cope with very simple delimiter arrangements.
>>
>
> var a = t.replace(/,/g,'$comma$').split('$comma$');

This is interesting. It's using the regex to do the search, but then it
uses the string (which is immune from the bug) to do the split!

Gerry Hickman

unread,
Aug 30, 2009, 7:41:30 AM8/30/09
to
Dr J R Stockton wrote:

> NOW there is.
>
> t = 'one,two,,four,,,seven,eight';
>
> String.prototype.Split = function() {
> var A = [], S= "", J
> for (J=0 ; J<this.length ; J++) {
> if (this.charAt(J)==",") { A.push(S) ; S = "" } else S += this.charAt(J) }
> if (S>"") A.push(S)
> return A }
>
> X = t.Split().join("+") // one+two++four+++seven+eight

Thanks. This works, but perhaps would fall over with more complex
delimiter arrangements such as

"username", "lastname, firstname","nextthing"

> It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

I just had a look at the FAQ, is there something specific I need to look at?

Gerry Hickman

unread,
Aug 30, 2009, 3:58:38 PM8/30/09
to
Gerry Hickman wrote:

> Evertjan. wrote:
>> var a = t.replace(/,/g,'$comma$').split('$comma$');

I have now run some tests and come up with the code below. In theory it
can deal with quoted fields, delimiters within quoted fields, empty
fields, empty quoted fields, leading delimiters, trailing delimiters,
and so on... Interested on any further comments to improve.

<job>
<!--
-->
<script language="JScript">

var sLine = ',one,"t,wo",,four,,"",seven,eight';
var aLine = line2ary(sLine, ",");
showAry(aLine);

var sLine = 'adalospq,"Smith,
Andrew","CN=adalospq,OU=2001,OU=HR,DC=child,DC=domain",\\\\server1\\share2$';
var aLine = line2ary(sLine, ",");
showAry(aLine);

var sLine = 'arcrgeya::HR Admin 3:s3cr3tpw:HR:Data1:';
var aLine = line2ary(sLine, ":");
showAry(aLine);

// -------------------- Functions --------------------

function line2ary(sLine, sDelim) {
// Line 2 Array

var sHardDelim = "$comma$";

var reDelim = new RegExp(sDelim +
"\\s*(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))","g");
var reQuotes = /^\"|\"$/g;
var reBadDelims = new RegExp("^" + sDelim + "|" + sDelim + "$","g");

// Remove leading, trailing instances of delim
var sLine = sLine.replace(reBadDelims, "");

// Convert to hard delimiters
var sLine = sLine.replace(reDelim,sHardDelim);

// Split using string constructor
var aFields = sLine.split(sHardDelim);

// Remove leading / trailling quotes
for (var i in aFields) {
aFields[i] = aFields[i].replace(reQuotes, "");
}
return aFields;
}

function showAry(aAry) {
// Show the array
var sOut = "";
trace("Length is " + aAry.length);
for (var i in aAry) {
sOut += "[" + aAry[i] + "]";
}
trace(sOut);
}

function trace(sMsg) {
WScript.Echo(sMsg);
}

</script>
</job>

Gerry Hickman

unread,
Aug 30, 2009, 5:13:01 PM8/30/09
to
Gerry Hickman wrote:

> I have now run some tests and come up with the code below.

Quotes removal wasn't strict enough, this version improves quote removal
and has better comments, run under cscript Split.wsf

<job>
<!--
Split a delimited line of text into fields

Changes:
Removal of quotes wasn't strict enough

Old:
var reQuotes = /^\"|\"$/g; // not strict enough


aFields[i] = aFields[i].replace(reQuotes, "");

New:
var reQuotes = /^\"(.*)\"$/; // must have quotes at start/finish, allow
empty
aFields[i] = aFields[i].replace(reQuotes, "$1");

-->
<script language="JScript">

// Test normal CSV
var sLine = 'one,two,three,four';


var aLine = line2ary(sLine, ",");
showAry(aLine);

// Test delimiter within quotes, leading delim, empty non-quoted, empty
quoted


var sLine = ',one,"t,wo",,four,,"",seven,eight';
var aLine = line2ary(sLine, ",");
showAry(aLine);

// Test delimiter within quotes (another example)


var sLine = 'adalospq,"Smith,
Andrew","CN=adalospq,OU=2001,OU=HR,DC=child,DC=domain",\\\\server1\\share2$';
var aLine = line2ary(sLine, ",");
showAry(aLine);

// Test different delim, empty field, trailing delim


var sLine = 'arcrgeya::HR Admin 3:s3cr3tpw:HR:Data1:';
var aLine = line2ary(sLine, ":");
showAry(aLine);

// -------------------- Functions --------------------

function line2ary(sLine, sDelim) {
// Line 2 Array

var sHardDelim = "$comma$";

var reDelim = new RegExp(sDelim +
"\\s*(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))","g");

var reQuotes = /^\"(.*)\"$/;


var reBadDelims = new RegExp("^" + sDelim + "|" + sDelim + "$","g");

// Remove leading, trailing instances of delim
var sLine = sLine.replace(reBadDelims, "");

// Convert to hard delimiters
var sLine = sLine.replace(reDelim,sHardDelim);

// Split using string constructor
var aFields = sLine.split(sHardDelim);

// Remove leading / trailling quotes
for (var i in aFields) {

aFields[i] = aFields[i].replace(reQuotes, "$1");

Thomas Sun [MSFT]

unread,
Aug 31, 2009, 5:30:35 AM8/31/09
to
Hi Gerry,

If the string is using comma to separate name and using quotation mark to
include name, such as " "username", "lastname, firstname","nextthing" ", we
can use ' " ' to split it and then remove ' , '. For example, we can use
follow code to do this:
==============================
<script type="text/javascript">

var result = '', tempStr = '';
var element;
var t = '"username", " lastname, firstname","nextthing"';
for (var j = 0; j < t.length; j++) {
if (t.charAt(j) != ' ')
tempStr += t.charAt(j);
}

var n = tempStr.split('"');
for (var i = 0; i < n.length; i++) {
element = n[i];
if (element != undefined && element != ',' && element !=
'') {
result += element + ' ';
}
}

alert(result);
</script>
=============================

What format of the string do you want? I understand that it will give
customer well experience if we can handle all strings. But I think it is
hard to find a solution to parse the string with many different formats
correctly. It would be better that we can specify the string format and
then coding basing on it.

Besides, we also can consider using another delimiter, such as '; ', to
separate name. By doing so, it makes coding easier.

I look forward to receiving hearing from you.


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Dr J R Stockton

unread,
Aug 31, 2009, 2:00:22 PM8/31/09
to
In microsoft.public.scripting.jscript message <#P3XRbWKKHA.3992@TK2MSFTN
GP05.phx.gbl>, Sun, 30 Aug 2009 12:41:30, Gerry Hickman
<gerry...@newsgroup.nospam> posted:

>Dr J R Stockton wrote:
>
>> NOW there is.
>> t = 'one,two,,four,,,seven,eight';
>> String.prototype.Split = function() {
>> var A = [], S= "", J
>> for (J=0 ; J<this.length ; J++) {
>> if (this.charAt(J)==",") { A.push(S) ; S = "" } else S +=
>>this.charAt(J) }
>> if (S>"") A.push(S)
>> return A }
>> X = t.Split().join("+") // one+two++four+++seven+eight
>
>Thanks. This works, but perhaps would fall over with more complex
>delimiter arrangements such as
>
>"username", "lastname, firstname","nextthing"

Extend the question, and an extended answer is needed. For that case,
you could count quotes (mod 2) and recognise only unquoted commas.

>> It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
>
>I just had a look at the FAQ, is there something specific I need to look at?

Not, as I recall, for this question; but you and others might find
something there that's useful sometime.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
NOT <URL:http://support.codegear.com/newsgroups/>: news:borland.* Guidelines

Gerry Hickman

unread,
Sep 1, 2009, 11:42:25 AM9/1/09
to
Hello Thomas,

Thnak you for the help with this.

Are you able to see all the replies in this thread? There are around 12
posts in total to date.

The key point is that there appears to be a BUG in the Microsoft regex
implementation of the JScript String.split() method.

// cscript split.js
// Split string

var t = 'one,two,,four,,,seven,eight';
var a = t.split(",");


var n = a.length;
WScript.Echo(n); // prints 8

var a = t.split(/,/);
var n = a.length;
WScript.Echo(n); // prints 5

Firefox and Chrome return 8 in both cases, which I believe is correct. Do
you agree this is a BUG in Microsoft JScript?

In relation to splitting delimited files that have quoted fields, delimiters
within quotes, empty fields, non-quoted fields, and leading/trailling
delimiters, I believe the code examples I posted on the 30th Aug 09 are the
best solution I've seen so far.

Thanks.

--
Gerry Hickman
London (UK)

"Thomas Sun [MSFT]" <v-t...@online.microsoft.com> wrote in message
news:RLMd82hK...@TK2MSFTNGHUB02.phx.gbl...

Thomas Sun [MSFT]

unread,
Sep 2, 2009, 12:40:36 AM9/2/09
to
Hi Gerry,

Thanks for your response.

I can reproduce the issue that the String.split() using regular expression
as parameter in JavaScript has different behaviors in IE and
Mozilla/Firefox. I have located the record in our internal system and it is
a known issue. Currently, the issue is not fixed yet and the current
scripting engine will be replaced by a new one in IE 9.

You also can post the feedback on the Connect Website
(https://connect.microsoft.com/IE/Feedback). Our developer will evaluate
them seriously and take them into consideration when designing future
release of the product.

Thanks,
Thomas


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
>X-Tomcat-NG: microsoft.public.scripting.jscript

Gerry Hickman

unread,
Sep 2, 2009, 4:44:31 PM9/2/09
to
> I can reproduce the issue that the String.split() using regular expression
> as parameter in JavaScript has different behaviors in IE and
> Mozilla/Firefox. I have located the record in our internal system and it is
> a known issue. Currently, the issue is not fixed yet and the current
> scripting engine will be replaced by a new one in IE 9.
>
> You also can post the feedback on the Connect Website
> (https://connect.microsoft.com/IE/Feedback). Our developer will evaluate
> them seriously and take them into consideration when designing future
> release of the product.

Hello Thomas,

Thanks for confirmation of this problem. That was the key point of my
post. Please note that I'm using WSH on Vista, I'm not using IE. Will
the IE9 fix also fix the issue in WSH?

Thanks.

Evertjan.

unread,
Sep 2, 2009, 6:11:47 PM9/2/09
to
Gerry Hickman wrote on 02 sep 2009 in
microsoft.public.scripting.jscript:

>> I can reproduce the issue that the String.split() using regular
>> expression as parameter in JavaScript has different behaviors in IE
>> and Mozilla/Firefox. I have located the record in our internal system
>> and it is a known issue. Currently, the issue is not fixed yet and
>> the current scripting engine will be replaced by a new one in IE 9.
>>
>> You also can post the feedback on the Connect Website
>> (https://connect.microsoft.com/IE/Feedback). Our developer will
>> evaluate them seriously and take them into consideration when
>> designing future release of the product.
>
> Hello Thomas,
>
> Thanks for confirmation of this problem. That was the key point of my
> post. Please note that I'm using WSH on Vista, I'm not using IE. Will
> the IE9 fix also fix the issue in WSH?

It is not an IE fix,
but a MS-script engine fix.

So yes, as w/cscript and IE use the same script engine.

The big Q is, when this will be implemented, 2011?

And when are IE6, IE7, IE8 no more in use,
because untill then you cannot trust split()
in clientside web applications.

Thomas Sun [MSFT]

unread,
Sep 3, 2009, 6:16:12 AM9/3/09
to
Hi Evertjan and Gerry,

Yes, it is a known issue on MS script engine and Microsoft will release the
new script engine as soon as possible. Improving the quality of our
products and services is a never ending process for Microsoft.

Currently, you can use the follow workaround for split method issue on
cross browser. For example:
=============================
<script type="text/javascript">

// Cross-Browser Split 1.0
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
// Consistent cross-browser, ECMA-262 v3 compliant split


// avoid running twice, which would break the reference to the
native `split`
if (!window.cbSplit) {

var cbSplit = function(str, separator, limit) {
// if `separator` is not a regex, use the native `split`
if (Object.prototype.toString.call(separator) !==
"[object RegExp]")
return cbSplit._nativeSplit.call(str, separator,
limit);

var output = [],
lastLastIndex = 0,
flags = (separator.ignoreCase ? "i" : "") +
(separator.multiline ? "m" : "") +
(separator.sticky ? "y" : ""),
separator = RegExp(separator.source, flags + "g"), // make `global` and
avoid `lastIndex` issues
separator2, match, lastIndex, lastLength;

str = str + ""; // type conversion
if (!cbSplit._compliantExecNpcg)
separator2 = RegExp("^" + separator.source +
"$(?!\\s)", flags); // doesn't need /g or /y, but they don't hurt

// behavior for `limit`: if it's...
// - `undefined`: no limit.
// - `NaN` or zero: return an empty array.
// - a positive number: use `Math.floor(limit)`.
// - a negative number: no limit.
// - other: type-convert, then use the above rules.
if (limit === undefined || +limit < 0) {
limit = Infinity;
} else {
limit = Math.floor(+limit);
if (!limit)
return [];
}

while (match = separator.exec(str)) {
lastIndex = match.index + match[0].length; //
`separator.lastIndex` is not reliable cross-browser

if (lastIndex > lastLastIndex) {
output.push(str.slice(lastLastIndex,
match.index));

// fix browsers whose `exec` methods don't
consistently return `undefined` for nonparticipating capturing groups
if (!cbSplit._compliantExecNpcg && match.length
> 1) {
match[0].replace(separator2, function() {
for (var i = 1; i < arguments.length -
2; i++) {
if (arguments[i] === undefined)
match[i] = undefined;
}
});
}

if (match.length > 1 && match.index <
str.length)
Array.prototype.push.apply(output,
match.slice(1));

lastLength = match[0].length;
lastLastIndex = lastIndex;

if (output.length >= limit)
break;
}

if (separator.lastIndex === match.index)
separator.lastIndex++; // avoid an infinite loop
}

if (lastLastIndex === str.length) {
if (!separator.test("") || lastLength)
output.push("");
} else {
output.push(str.slice(lastLastIndex));
}

return output.length > limit ? output.slice(0, limit) :
output;
};

cbSplit._compliantExecNpcg = /()??/.exec("")[1] ===
undefined; // "NPCG": nonparticipating capturing group
cbSplit._nativeSplit = String.prototype.split;

}

// for convenience...
String.prototype.split = function(separator, limit) {
return cbSplit(this, separator, limit);
};


var t1 = 'one,two,,four,,,seven,eight';
var a = t1.split(",");
var n = a.length;
alert(n);
var a1 = t1.split(/,/);
var n1 = a1.length;
alert(n1);

</script>
============================

This work around is referred from#
http://blog.stevenlevithan.com/archives/cross-browser-split

Thanks,
Thomas


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support

This response contains a reference to a third party World Wide Web site.
Microsoft is providing this information as a convenience to you. Microsoft
does not control these sites and has not tested any software or information
found on these sites; therefore, Microsoft cannot make any representations
regarding the quality, safety, or suitability of any software or
information found there. There are inherent dangers in the use of any
software found on the Internet, and Microsoft cautions you to make sure
that you completely understand the risk before retrieving any software from
the Internet.
--------------------

Evertjan.

unread,
Sep 3, 2009, 6:37:38 AM9/3/09
to
Thomas Sun [MSFT] wrote on 03 sep 2009 in
microsoft.public.scripting.jscript:

> Hi Evertjan and Gerry,
>
> Yes, it is a known issue on MS script engine and Microsoft will
> release the new script engine as soon as possible. Improving the
> quality of our products and services is a never ending process for
> Microsoft.
>
> Currently, you can use the follow workaround for split method issue on
> cross browser.

Dear Thomas,

Is this really better than simple one liner trick I proposed?
[Even no MIT licence, I put this in the public domain]

var arr = txt.replace(/,/g,'$anything$').split('$anything$');

and you do not have to avoid running it twice,
only the string '$anything$' should reasonably not be part of the
original textstring.

[Please do not toppost on usenet]

Evertjan.

Dr J R Stockton

unread,
Sep 3, 2009, 11:53:50 AM9/3/09
to
In microsoft.public.scripting.jscript message <hyF9Le4KKHA.6996@TK2MSFTN
GHUB02.phx.gbl>, Wed, 2 Sep 2009 04:40:36, "Thomas Sun [MSFT]" <v-
th...@online.microsoft.com> posted:

>I can reproduce the issue that the String.split() using regular expression
>as parameter in JavaScript has different behaviors in IE and
>Mozilla/Firefox.

Of at least equal importance : the IE behaviour is not supported by
ISO/IEC 16262, of which I expect you have a PDF copy.


> I have located the record in our internal system and it is
>a known issue. Currently, the issue is not fixed yet and the current
>scripting engine will be replaced by a new one in IE 9.

Indeed, page
<http://msdn.microsoft.com/en-us/library/t5az126b(VS.85).aspx>
knows about the issue.

Will the new engine fix the .toFixed bug (not mentioned on
<http://msdn.microsoft.com/en-us/library/sstyff0z(VS.85).aspx>) which
means for example that 0.007.toFixed(2) returns "0.00"?

Will the ISO 8601 Week Number bug in VBScript DatePart be fixed? The MS
site does have an alternative (correct answers; but atrocious code)
function. My Web site refers, and has better code.


>--
>Best

A space after those two dashes would be helpful.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm vb-dates.htm pas-time.htm critdate.htm etc.

Thomas Sun [MSFT]

unread,
Sep 3, 2009, 11:51:00 PM9/3/09
to
Hi John,

Thanks for your information.

>>Will the new engine fix the .toFixed bug (not mentioned on
>><http://msdn.microsoft.com/en-us/library/sstyff0z(VS.85).aspx>) which
>>means for example that 0.007.toFixed(2) returns "0.00"?

Yes, it will return "0.00". The toFixed Method doesn't round down. If you
expect that result is "0.01", you can try the follow code:
=========================
<script type="text/jscript">

Number.prototype.toFixed = function(precision) {
var obj = Math.pow(10, precision || 0);
return String(Math.round(this * obj ) / obj );
}

</script>
========================

>>Will the ISO 8601 Week Number bug in VBScript DatePart be fixed? The MS
>>site does have an alternative (correct answers; but atrocious code)
>>function. My Web site refers, and has better code.

Based on my research, I located this known issue in our internal system and
its status is leave the behavior as-is and Microsoft issued a KB on
http://support.microsoft.com/kb/200299 to supply workarounds.

You also can post the feedback on the Connect Website
(https://connect.microsoft.com/IE/Feedback). Our developer will evaluate
them seriously and take them into consideration when designing future
release of the product.

--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
>Path:
TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS02.phx.gbl!newsfeed0
0.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!weretis.net!feeder1
.news.weretis.net!feeder.news-service.com!feeder.news-service.com!cyclone01.
ams2.highwinds-media.com!news.highwinds-media.com!npeersf01.ams.highwinds-me
dia.com!newsfe21.ams2.POSTED!7564ea0f!not-for-mail
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.scripting.jscript:4003
>X-Tomcat-NG: microsoft.public.scripting.jscript

Dr J R Stockton

unread,
Sep 5, 2009, 5:05:13 PM9/5/09
to
In microsoft.public.scripting.jscript message <rc#vxLRLKHA.7496@TK2MSFTN
GHUB02.phx.gbl>, Fri, 4 Sep 2009 03:51:00, "Thomas Sun [MSFT]" <v-
th...@online.microsoft.com> posted:

JScript :


>>>Will the new engine fix the .toFixed bug (not mentioned on
>>><http://msdn.microsoft.com/en-us/library/sstyff0z(VS.85).aspx>) which
>>>means for example that 0.007.toFixed(2) returns "0.00"?
>
>Yes, it will return "0.00". The toFixed Method doesn't round down.

?? Method toFixed should round to the nearest, and away from zero if
two are equally near.


>If you
>expect that result is "0.01", you can try the follow code:
>=========================
> <script type="text/jscript">
>
> Number.prototype.toFixed = function(precision) {
> var obj = Math.pow(10, precision || 0);
> return String(Math.round(this * obj ) / obj );
> }
>
> </script>
>========================

That does what is wanted, at least in that case. I use my own code for
non-integer number to string.

See the yellow box at
<URL:http://www.merlyn.demon.co.uk/js-round.htm#toF>, comparing toFixed
in IE with toFixed in other browsers.


VBScript :

> >>Will the ISO 8601 Week Number bug in VBScript DatePart be fixed? The MS
>>>site does have an alternative (correct answers; but atrocious code)
>>>function. My Web site refers, and has better code.
>
>Based on my research, I located this known issue in our internal system and
>its status is leave the behavior as-is and Microsoft issued a KB on
>http://support.microsoft.com/kb/200299 to supply workarounds.

That alternate code is bloated and inefficient; its author should have
thought more before implementing it.

See <URL:http://www.merlyn.demon.co.uk/vb-date2.htm#DP>, using a browser
that supports VBScript.

>You also can post the feedback on the Connect Website
>(https://connect.microsoft.com/IE/Feedback). Our developer will evaluate
>them seriously and take them into consideration when designing future
>release of the product.

I did that, some while ago.

The above KB describes the error imperfectly (it omits 2101-01-02 =
2100-W52-7).

The bug report is specifically for
DatePart("ww", AnyDate, vbMonday, vbFirstFourDays)

It occurs to me unlikely that the error in the routine affects only the
combination vbMonday, vbFirstFourDays - but that is the only one
that interests me.

They should know that date code ought to be tested over all days in at
least 28 & preferably 400 years.

One is most unimpressed to see that new systems are being distributed
with an old acknowledged bug that has a known fix available.

Page <http://msdn.microsoft.com/en-us/library/20ee97hz(VS.80).aspx> says
"(complies with ISO standard 8601, section 3.17)" - naively not saying
which version of the standard - does not seem to match those of 2000 &
2004, could be the ancient 1988 one - does not mention the bug or its
fix.

Strangely, my IE8 does not load Microsoft pages such as those mentioned;
Firefox has no difficulty.

Note cross-post; consider setting follow-up.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm

Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

Thomas Sun [MSFT]

unread,
Sep 6, 2009, 10:35:06 PM9/6/09
to
Hi John,

Thanks for your feedback on Connect Website. Our developer will evaluate
your feedback seriously and give your response.


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------

Dr J R Stockton

unread,
Sep 7, 2009, 6:38:52 PM9/7/09
to
In microsoft.public.scripting.jscript message <$fN3ZP2LKHA.2084@TK2MSFTN
GHUB02.phx.gbl>, Mon, 7 Sep 2009 02:35:06, "Thomas Sun [MSFT]" <v-
th...@online.microsoft.com> posted:

>>Strangely, my IE8 does not load Microsoft pages such as those mentioned;
>>Firefox has no difficulty.

Turns out it would not load ANY external pages at the time; but it cured
itself. If there is a problem, it's in my IE8, WinXP, or system; not at
your site. The problem has, however, reappeared.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Thomas Sun [MSFT]

unread,
Sep 7, 2009, 10:23:25 PM9/7/09
to

Hi John,

To better understand the issue why IE 8 cannot load page, please confirm
the follow information:

#1. If we disable Add-ons ("Tools" | "Manage Add-ons" | "Enable or Disable
Add-ons"), do we still have the problem? This can eliminate the possibility
that third party Add-ons are causing problems.

#2. Please check whether we specify the proxy server for IE ("Tools" |
"Internet Options" | "Connections" | "LAN settings"). If so, please make
sure it is correct.

#3. Please temporarily disable antispyware and antivirus software which can
block IE. Note: This step may make a computer or a network more vulnerable
to attack by malicious users or by malicious software such as viruses. If
IE works, please configure antivirus software not block it.

#4. If above methods did not work for you, please try to reset IE 8
settings. For more information, see
<http://support.microsoft.com/kb/923737>.


I look forward to receiving your test results.


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
>

Gerry Hickman

unread,
Sep 8, 2009, 2:47:56 PM9/8/09
to
Thomas Sun [MSFT] wrote:
> Yes, it is a known issue on MS script engine and Microsoft will release the
> new script engine as soon as possible. Improving the quality of our
> products and services is a never ending process for Microsoft.

Thanks Thomas,

Please could you further clarify how the updated script engine will be
distributed? For example, do we assume WSH is part of IE? Will it work
on older o/s such as XP/2003?

My version of cscript on Vista is 5.7

Dr J R Stockton

unread,
Sep 10, 2009, 10:45:19 AM9/10/09
to
In microsoft.public.scripting.jscript message <CERqhtCMKHA.2084@TK2MSFTN
GHUB02.phx.gbl>, Tue, 8 Sep 2009 02:23:25, "Thomas Sun [MSFT]" <v-
th...@online.microsoft.com> posted:

>To better understand the issue why IE 8 cannot load page, please confirm
>the follow information:
>
>#1. If we disable Add-ons ("Tools" | "Manage Add-ons" | "Enable or Disable
>Add-ons"), do we still have the problem? This can eliminate the possibility
>that third party Add-ons are causing problems.
>
>#2. Please check whether we specify the proxy server for IE ("Tools" |
>"Internet Options" | "Connections" | "LAN settings"). If so, please make
>sure it is correct.
>
>#3. Please temporarily disable antispyware and antivirus software which can
>block IE. Note: This step may make a computer or a network more vulnerable
>to attack by malicious users or by malicious software such as viruses. If
>IE works, please configure antivirus software not block it.
>
>#4. If above methods did not work for you, please try to reset IE 8
>settings. For more information, see
><http://support.microsoft.com/kb/923737>.
>
>
>I look forward to receiving your test results.


It does, or did, not occur reproducibly, so testing is not easy.

The main purpose of that article was to exonerate the MS Web Site,
suspected in the previous article; my usual browser is Firefox 3.0.13.

Vince Xu [MSFT]

unread,
Sep 14, 2009, 6:12:35 AM9/14/09
to
Hello Gerry,

Thomas is off these days. I'm his backup.
As far as I know, WSH is party of IE. It is existing since Windows 98. The
lastest JScript is version5.8, please check the following link:
http://blogs.msdn.com/ie/archive/2009/03/24/what-s-new-in-jscript-for-ie8.as
px


Sincerely,

Vince Xu

Microsoft Online Support

Evertjan.

unread,
Sep 15, 2009, 2:43:23 PM9/15/09
to
Vince Xu [MSFT] wrote on 14 sep 2009 in
microsoft.public.scripting.jscript:
> Hello Gerry,
>
> Thomas is off these days. I'm his backup.
> As far as I know, WSH is party of IE. It is existing since Windows 98.

Dear backup Vince,

This is usenet you are responding to the NG,
this is not email.

Please always quote on usenet.

Please repair your usenet signature,
start it with dash-dash-space-return.
[Your email signature should also conform to that, but that is OT here]

> The lastest JScript is version5.8, please check the following link:
> http://blogs.msdn.com/ie/archive/2009/03/24/what-s-new-in-jscript-for-i
> e8.as px

Interesting page, thanks.

See also:

<http://blogs.msdn.com/ie/archive/2009/01/13/responding-to-change-updated-
getter-setter-syntax-in-ie8-rc-1.aspx>

asdf

unread,
Dec 6, 2009, 4:46:16 AM12/6/09
to
"not easy"


exonerate
v. acquit, absolve, clear of blame, declare innocent; relieve of an
obligation, free from a duty


Shakespeare ? Newton

Other shot the long bow for apples before that ?

All times are London ?

The British Pound the oldest "still' valid Paper fiat Currency ?

---------------------------------------------------------------------------------------------------

You are good !

Your time to reality is a little lagging though.


>
> The main purpose of that article was to exonerate the MS Web Site,

IMG_TitleMenuOpen

Brian W

unread,
Jul 26, 2010, 8:06:05 PM7/26/10
to
If you'd like to take a look at a general solution to this problem in the form of a free, open-source javascript object, you can visit http://splitterjsobj.sourceforge.net/ for a live demo (and download). The object has the following features:

- Pairs of user-defined quote characters can be used to escape the delimiter (prevent a split inside quotes). The quotes can be escaped with a user-defined escape char, and/or by "double quote escape." The escape char can be escaped (with itself). In one of the 5 output arrays (properties of the object), output is unescaped. For example, "a\\\"b" is unescaped as a\"b.
- Split on an array of delimiters; parse a file (such as CSV) in one call. (The output arrays will be nested.)
- All escape sequences recognized by javascript can be evaluated during the split process and/or in a preprocess.
- Callback functionality
- Cross-browser consistency

The object is also available as a jQuery plugin, visit: http://plugins.jquery.com/project/splitterjsobj

v-thsu wrote:

Hi Gerry,If the string is using comma to separate name and using quotation
31-Aug-09

Hi Gerry,

alert(result);
</script>
=============================

Microsoft Online Partner Support

--------------------
this.charAt(J) }
at?

Previous Posts In This Thread:

On Friday, August 28, 2009 10:13 AM
Gerry Hickman wrote:

CSV and regex s.split(",") and empty fields
Hi,

I can use s.split(",") to split a CSV file into fields when the file looks
like this

one, two, three

BUT, in real life, my input file looks like this

one, two,,four,,,seven,eight

Note that some fields are empty. When I try to use s.split(",") it ignores
the empty fields and my array ends up with only five elements instead of
eight. I would like to end up with an eight element array where some fields
contain an empty string.

If it cannot be done with s.split(), is there a function that would do this?

Thanks.

--
Gerry Hickman
London (UK)

On Friday, August 28, 2009 10:45 AM
Evertjan. wrote:

Gerry Hickman wrote on 28 aug 2009 inmicrosoft.public.scripting.
Gerry Hickman wrote on 28 aug 2009 in
microsoft.public.scripting.jscript:


Not true!

<script type='text/javascript'>
var t = 'one,two,,four,,,seven,eight';
var n = t.split(',').length;
alert(n);
</script>

returns 8.

using regex:

var n = t.split(/,/).length;

also returns 8.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Friday, August 28, 2009 4:16 PM
Gerry Hickman wrote:

Hello,Sorry, I did not test properly, and made a mess of the original post.
Hello,

Sorry, I did not test properly, and made a mess of the original post. I
should have explained I am running under WSH, not in a browser. Either
way, when using a string delimiter, it appears to work!

However, when using regex, I do not see the same results you posted
below. Here is the example code - run under cscript

// cscript split.js
// Split string

var t = 'one,two,,four,,,seven,eight';
var a = t.split(",");
var n = a.length;


WScript.Echo(n); // prints 8
var a = t.split(/,/);
var n = a.length;
WScript.Echo(n); // prints 5

Do you get the same results?


Evertjan. wrote:


--
Gerry Hickman (London UK)

On Friday, August 28, 2009 6:43 PM
Evertjan. wrote:

Gerry Hickman wrote on 28 aug 2009 in microsoft.public.scripting.


Gerry Hickman wrote on 28 aug 2009 in microsoft.public.scripting.jscript:

[Please do not toppost on usenet]


yes:

var n = t.split(/,/).length;

cscript and IE8 return 5

FF and Chrome return 8


So definitly a serious error in the M$ jscript engine.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Saturday, August 29, 2009 12:51 PM
Gerry Hickman wrote:

Evertjan.
Evertjan. wrote:

OK, is there a way to create a new split() function that would accept a
RegEx and work correctly?


--
Gerry Hickman (London UK)

On Saturday, August 29, 2009 2:37 PM
Evertjan. wrote:

Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.
Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.jscript:


What do you think?
and what did you try?
and why do you need the regex version?

I think there is.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Saturday, August 29, 2009 2:48 PM
Gerry Hickman wrote:

Evertjan. wrote:I'd like to design a new one, but need some help to do it.
Evertjan. wrote:


I'd like to design a new one, but need some help to do it.

One other possible workaround would be to hack the regex in order to
"trick" the split method into working correctly. The closest thing I have
found so far is this:

var t = 'one,two,,four,,,seven,eight';
var a = t.split(/(?=,)/);


var n = a.length;
WScript.Echo(n); // prints 8

but you end up with this (note leading commas)

one
,two
,
,four
,
,
,seven
,eight

I need to get the regex version working, because in real life the string
version will only cope with very simple delimiter arrangements.

Thanks.

--
Gerry Hickman (London UK)

On Saturday, August 29, 2009 3:09 PM
Evertjan. wrote:

Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.
Gerry Hickman wrote on 29 aug 2009 in microsoft.public.scripting.jscript:


var a = t.replace(/,/g,'$comma$').split('$comma$');

--


Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Saturday, August 29, 2009 4:44 PM


Dr J R Stockton wrote:

In microsoft.public.scripting.jscript message <#ZO38m#JKHA.1488@TK2MSFTNGP03.


In microsoft.public.scripting.jscript message <#ZO38m#JKHA...@TK2MSFTNGP03.ph
x.gbl>, Fri, 28 Aug 2009 15:13:36, Gerry Hickman
<gerry...@newsgroup.nospam> posted:


NOW there is.

t = 'one,two,,four,,,seven,eight';

String.prototype.Split = function() {
var A = [], S= "", J
for (J=0 ; J<this.length ; J++) {
if (this.charAt(J)==",") { A.push(S) ; S = "" } else S += this.charAt(J) }
if (S>"") A.push(S)
return A }

X = t.Split().join("+") // one+two++four+++seven+eight

You might check what happens id the first or last character is a comma.

it is a good idea to read the newsgroup c.l.j and its FAQ. See below.

--


(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3

<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

On Sunday, August 30, 2009 6:28 AM
Evertjan. wrote:

Dr J R Stockton wrote on 29 aug 2009 inmicrosoft.public.scripting.
Dr J R Stockton wrote on 29 aug 2009 in
microsoft.public.scripting.jscript:


This does not help, John,
as the split(',') is working.

It is the split(/,/) that is buggy
in IE and w/cscript.

The OP stipulated that he needed complex regex split in cscript.

--


Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Sunday, August 30, 2009 7:25 AM
Gerry Hickman wrote:

Evertjan. wrote:This is interesting.
Evertjan. wrote:

This is interesting. it is using the regex to do the search, but then it


uses the string (which is immune from the bug) to do the split!

Thanks.

--
Gerry Hickman (London UK)

On Sunday, August 30, 2009 7:41 AM
Gerry Hickman wrote:

Dr J R Stockton wrote:Thanks.


Dr J R Stockton wrote:


Thanks. This works, but perhaps would fall over with more complex
delimiter arrangements such as

"username", "lastname, firstname","nextthing"

I just had a look at the FAQ, is there something specific I need to look at?

--
Gerry Hickman (London UK)

On Sunday, August 30, 2009 3:58 PM
Gerry Hickman wrote:

Gerry Hickman wrote:I have now run some tests and come up with the code below.
Gerry Hickman wrote:


I have now run some tests and come up with the code below. In theory it
can deal with quoted fields, delimiters within quoted fields, empty
fields, empty quoted fields, leading delimiters, trailing delimiters,
and so on... Interested on any further comments to improve.

<job>
<!--
-->
<script language="JScript">

var sLine = ',one,"t,wo",,four,,"",seven,eight';


var aLine = line2ary(sLine, ",");
showAry(aLine);

var sLine = 'adalospq,"Smith,


Andrew","CN=adalospq,OU=2001,OU=HR,DC=child,DC=domain",\\\\server1\\share2$';
var aLine = line2ary(sLine, ",");
showAry(aLine);

var sLine = 'arcrgeya::HR Admin 3:s3cr3tpw:HR:Data1:';


var aLine = line2ary(sLine, ":");
showAry(aLine);

// -------------------- Functions --------------------

function line2ary(sLine, sDelim) {
// Line 2 Array

var sHardDelim = "$comma$";

var reDelim = new RegExp(sDelim +
"\\s*(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))","g");

var reQuotes = /^\"|\"$/g;


var reBadDelims = new RegExp("^" + sDelim + "|" + sDelim + "$","g");

// Remove leading, trailing instances of delim
var sLine = sLine.replace(reBadDelims, "");

// Convert to hard delimiters
var sLine = sLine.replace(reDelim,sHardDelim);

// Split using string constructor
var aFields = sLine.split(sHardDelim);

// Remove leading / trailling quotes
for (var i in aFields) {

aFields[i] = aFields[i].replace(reQuotes, "");
}
return aFields;
}

function showAry(aAry) {
// Show the array
var sOut = "";
trace("Length is " + aAry.length);
for (var i in aAry) {
sOut += "[" + aAry[i] + "]";
}
trace(sOut);
}

function trace(sMsg) {
WScript.Echo(sMsg);
}

</script>
</job>

--
Gerry Hickman (London UK)

On Sunday, August 30, 2009 5:13 PM
Gerry Hickman wrote:

Gerry Hickman wrote:Quotes removal was not strict enough, this version
Gerry Hickman wrote:


Quotes removal was not strict enough, this version improves quote removal


and has better comments, run under cscript Split.wsf

<job>
<!--
Split a delimited line of text into fields

Changes:
Removal of quotes was not strict enough

-->
<script language="JScript">

// -------------------- Functions --------------------

var sHardDelim = "$comma$";

function trace(sMsg) {
WScript.Echo(sMsg);
}

</script>
</job>

--
Gerry Hickman (London UK)

On Monday, August 31, 2009 5:30 AM
v-thsu wrote:

Hi Gerry,If the string is using comma to separate name and using quotation
Hi Gerry,

alert(result);
</script>
=============================

Microsoft Online Partner Support

--------------------
this.charAt(J) }
at?

On Monday, August 31, 2009 2:00 PM


Dr J R Stockton wrote:

In microsoft.public.scripting.jscript message <#P3XRbWKKHA.
In microsoft.public.scripting.jscript message <#P3XRbWKKHA.3992@TK2MSFTN
<gerry...@newsgroup.nospam> posted:

Extend the question, and an extended answer is needed. For that case,
you could count quotes (mod 2) and recognise only unquoted commas.

Not, as I recall, for this question; but you and others might find

something there that is useful sometime.

--


(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;

On Tuesday, September 01, 2009 11:42 AM
Gerry Hickman wrote:

Hello Thomas,Thnak you for the help with this.
Hello Thomas,

Thnak you for the help with this.

Are you able to see all the replies in this thread? There are around 12
posts in total to date.

The key point is that there appears to be a BUG in the Microsoft regex
implementation of the JScript String.split() method.

// cscript split.js
// Split string

var t = 'one,two,,four,,,seven,eight';
var a = t.split(",");
var n = a.length;


WScript.Echo(n); // prints 8
var a = t.split(/,/);
var n = a.length;
WScript.Echo(n); // prints 5

Firefox and Chrome return 8 in both cases, which I believe is correct. Do
you agree this is a BUG in Microsoft JScript?

In relation to splitting delimited files that have quoted fields, delimiters
within quotes, empty fields, non-quoted fields, and leading/trailling
delimiters, I believe the code examples I posted on the 30th Aug 09 are the

best solution I have seen so far.

Thanks.

--
Gerry Hickman
London (UK)

On Wednesday, September 02, 2009 12:40 AM
v-thsu wrote:

Hi Gerry,Thanks for your response.I can reproduce the issue that the String.
Hi Gerry,

Thanks for your response.

I can reproduce the issue that the String.split() using regular expression


as parameter in JavaScript has different behaviors in IE and

Mozilla/Firefox. I have located the record in our internal system and it is


a known issue. Currently, the issue is not fixed yet and the current
scripting engine will be replaced by a new one in IE 9.

You also can post the feedback on the Connect Website


(https://connect.microsoft.com/IE/Feedback). Our developer will evaluate
them seriously and take them into consideration when designing future
release of the product.

Thanks,
Thomas


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
delimiters
the

On Wednesday, September 02, 2009 4:44 PM
Gerry Hickman wrote:

Hello Thomas,Thanks for confirmation of this problem.
Hello Thomas,

Thanks for confirmation of this problem. That was the key point of my

post. Please note that I am using WSH on Vista, I am not using IE. Will


the IE9 fix also fix the issue in WSH?

Thanks.

On Wednesday, September 02, 2009 6:11 PM
Evertjan. wrote:

Gerry Hickman wrote on 02 sep 2009 inmicrosoft.public.scripting.
Gerry Hickman wrote on 02 sep 2009 in
microsoft.public.scripting.jscript:

It is not an IE fix,
but a MS-script engine fix.

So yes, as w/cscript and IE use the same script engine.

The big Q is, when this will be implemented, 2011?

And when are IE6, IE7, IE8 no more in use,
because untill then you cannot trust split()
in clientside web applications.

--


Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Thursday, September 03, 2009 6:16 AM
v-thsu wrote:

Hi Evertjan and Gerry,Yes, it is a known issue on MS script engine and
Hi Evertjan and Gerry,

Yes, it is a known issue on MS script engine and Microsoft will release the
new script engine as soon as possible. Improving the quality of our
products and services is a never ending process for Microsoft.

Currently, you can use the follow workaround for split method issue on
cross browser. For example:
=============================
<script type="text/javascript">

// Cross-Browser Split 1.0


// MIT License
// Consistent cross-browser, ECMA-262 v3 compliant split


// avoid running twice, which would break the reference to the
native `split`
if (!window.cbSplit) {

var cbSplit = function(str, separator, limit) {
// if `separator` is not a regex, use the native `split`
if (Object.prototype.toString.call(separator) !==
"[object RegExp]")
return cbSplit._nativeSplit.call(str, separator,
limit);

var output = [],
lastLastIndex = 0,
flags = (separator.ignoreCase ? "i" : "") +
(separator.multiline ? "m" : "") +
(separator.sticky ? "y" : ""),
separator = RegExp(separator.source, flags + "g"), // make `global` and
avoid `lastIndex` issues
separator2, match, lastIndex, lastLength;

str = str + ""; // type conversion
if (!cbSplit._compliantExecNpcg)
separator2 = RegExp("^" + separator.source +

"$(?!\\s)", flags); // does not need /g or /y, but they do not hurt

// behavior for `limit`: if it is...


// - `undefined`: no limit.
// - `NaN` or zero: return an empty array.
// - a positive number: use `Math.floor(limit)`.
// - a negative number: no limit.
// - other: type-convert, then use the above rules.
if (limit === undefined || +limit < 0) {
limit = Infinity;
} else {
limit = Math.floor(+limit);
if (!limit)
return [];
}

while (match = separator.exec(str)) {
lastIndex = match.index + match[0].length; //
`separator.lastIndex` is not reliable cross-browser

if (lastIndex > lastLastIndex) {
output.push(str.slice(lastLastIndex,
match.index));

// fix browsers whose `exec` methods do not


consistently return `undefined` for nonparticipating capturing groups
if (!cbSplit._compliantExecNpcg && match.length

match[0].replace(separator2, function() {
for (var i = 1; i < arguments.length -
2; i++) {
if (arguments[i] === undefined)
match[i] = undefined;
}
});
}

if (match.length > 1 && match.index <
str.length)
Array.prototype.push.apply(output,
match.slice(1));

lastLength = match[0].length;
lastLastIndex = lastIndex;

if (output.length >= limit)
break;
}

if (separator.lastIndex === match.index)
separator.lastIndex++; // avoid an infinite loop
}

if (lastLastIndex === str.length) {
if (!separator.test("") || lastLength)
output.push("");
} else {
output.push(str.slice(lastLastIndex));
}

On Thursday, September 03, 2009 6:37 AM
Evertjan. wrote:

Thomas Sun [MSFT] wrote on 03 sep 2009 inmicrosoft.public.scripting.
Thomas Sun [MSFT] wrote on 03 sep 2009 in
microsoft.public.scripting.jscript:


Dear Thomas,

Is this really better than simple one liner trick I proposed?
[Even no MIT licence, I put this in the public domain]

var arr = txt.replace(/,/g,'$anything$').split('$anything$');

and you do not have to avoid running it twice,
only the string '$anything$' should reasonably not be part of the
original textstring.

[Please do not toppost on usenet]

Evertjan.

On Thursday, September 03, 2009 11:53 AM


Dr J R Stockton wrote:

In microsoft.public.scripting.jscript message <hyF9Le4KKHA.
In microsoft.public.scripting.jscript message <hyF9Le4KKHA.6996@TK2MSFTN


Of at least equal importance : the IE behaviour is not supported by
ISO/IEC 16262, of which I expect you have a PDF copy.

Indeed, page

Will the new engine fix the .toFixed bug (not mentioned on


<http://msdn.microsoft.com/en-us/library/sstyff0z(VS.85).aspx>) which
means for example that 0.007.toFixed(2) returns "0.00"?

Will the ISO 8601 Week Number bug in VBScript DatePart be fixed? The MS


site does have an alternative (correct answers; but atrocious code)
function. My Web site refers, and has better code.

A space after those two dashes would be helpful.

--


(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm

Dates - miscdate.htm estrdate.htm vb-dates.htm pas-time.htm critdate.htm etc.

On Thursday, September 03, 2009 11:51 PM
v-thsu wrote:

Hi John,Thanks for your information.Yes, it will return "0.00".
Hi John,

Thanks for your information.


Yes, it will return "0.00". The toFixed Method does not round down. If you


expect that result is "0.01", you can try the follow code:
=========================
<script type="text/jscript">

Number.prototype.toFixed = function(precision) {
var obj = Math.pow(10, precision || 0);
return String(Math.round(this * obj ) / obj );
}

</script>
========================


Based on my research, I located this known issue in our internal system and
its status is leave the behavior as-is and Microsoft issued a KB on
http://support.microsoft.com/kb/200299 to supply workarounds.

You also can post the feedback on the Connect Website


(https://connect.microsoft.com/IE/Feedback). Our developer will evaluate
them seriously and take them into consideration when designing future
release of the product.

--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
0.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!weretis.net!feeder1
news.weretis.net!feeder.news-service.com!feeder.news-service.com!cyclone01.
ams2.highwinds-media.com!news.highwinds-media.com!npeersf01.ams.highwinds-me
dia.com!newsfe21.ams2.POSTED!7564ea0f!not-for-mail
expression
v6.05.
acronyms
00index.htm
etc.

On Saturday, September 05, 2009 5:05 PM


Dr J R Stockton wrote:

In microsoft.public.scripting.jscript message <rc#vxLRLKHA.
In microsoft.public.scripting.jscript message <rc#vxLRLKHA.7496@TK2MSFTN

JScript :

?? Method toFixed should round to the nearest, and away from zero if
two are equally near.

That does what is wanted, at least in that case. I use my own code for
non-integer number to string.

See the yellow box at
<URL:http://www.merlyn.demon.co.uk/js-round.htm#toF>, comparing toFixed
in IE with toFixed in other browsers.


VBScript :


That alternate code is bloated and inefficient; its author should have
thought more before implementing it.

See <URL:http://www.merlyn.demon.co.uk/vb-date2.htm#DP>, using a browser
that supports VBScript.

I did that, some while ago.

The above KB describes the error imperfectly (it omits 2101-01-02 =
2100-W52-7).

The bug report is specifically for
DatePart("ww", AnyDate, vbMonday, vbFirstFourDays)

It occurs to me unlikely that the error in the routine affects only the
combination vbMonday, vbFirstFourDays - but that is the only one
that interests me.

They should know that date code ought to be tested over all days in at
least 28 & preferably 400 years.

One is most unimpressed to see that new systems are being distributed
with an old acknowledged bug that has a known fix available.

Page <http://msdn.microsoft.com/en-us/library/20ee97hz(VS.80).aspx> says
"(complies with ISO standard 8601, section 3.17)" - naively not saying
which version of the standard - does not seem to match those of 2000 &
2004, could be the ancient 1988 one - does not mention the bug or its
fix.

Strangely, my IE8 does not load Microsoft pages such as those mentioned;
Firefox has no difficulty.

Note cross-post; consider setting follow-up.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

On Sunday, September 06, 2009 10:35 PM
v-thsu wrote:

Hi John,Thanks for your feedback on Connect Website.
Hi John,

Thanks for your feedback on Connect Website. Our developer will evaluate
your feedback seriously and give your response.

--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
MS
and

On Monday, September 07, 2009 6:38 PM


Dr J R Stockton wrote:

In microsoft.public.scripting.jscript message <$fN3ZP2LKHA.
In microsoft.public.scripting.jscript message <$fN3ZP2LKHA.2084@TK2MSFTN


Turns out it would not load ANY external pages at the time; but it cured

itself. If there is a problem, it is in my IE8, WinXP, or system; not at


your site. The problem has, however, reappeared.

--


(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)

Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

On Monday, September 07, 2009 10:23 PM
v-thsu wrote:

Hi John,To better understand the issue why IE 8 cannot load page, please
Hi John,

To better understand the issue why IE 8 cannot load page, please confirm
the follow information:

Add-ons"), do we still have the problem? This can eliminate the possibility


that third party Add-ons are causing problems.

"Internet Options" | "Connections" | "LAN settings"). If so, please make
sure it is correct.

block IE. Note: This step may make a computer or a network more vulnerable


to attack by malicious users or by malicious software such as viruses. If
IE works, please configure antivirus software not block it.

settings. For more information, see
<http://support.microsoft.com/kb/923737>.


I look forward to receiving your test results.


--
Best Regards,
Thomas Sun

Microsoft Online Partner Support


--------------------
MIME.
links.
(SonOfRFC1036)
(SonOfRFC1036)

On Tuesday, September 08, 2009 2:47 PM
Gerry Hickman wrote:

Thomas Sun [MSFT] wrote:Thanks Thomas,Please could you further clarify how the
Thomas Sun [MSFT] wrote:

Thanks Thomas,

Please could you further clarify how the updated script engine will be
distributed? For example, do we assume WSH is part of IE? Will it work
on older o/s such as XP/2003?

My version of cscript on Vista is 5.7

--
Gerry Hickman (London UK)

On Thursday, September 10, 2009 10:45 AM


Dr J R Stockton wrote:

In microsoft.public.scripting.jscript message <CERqhtCMKHA.
In microsoft.public.scripting.jscript message <CERqhtCMKHA.2084@TK2MSFTN


It does, or did, not occur reproducibly, so testing is not easy.

The main purpose of that article was to exonerate the MS Web Site,


suspected in the previous article; my usual browser is Firefox 3.0.13.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)

Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

On Monday, September 14, 2009 6:12 AM
v-vince wrote:

Hello Gerry,Thomas is off these days. I am his backup.
Hello Gerry,

Thomas is off these days. I am his backup.
As far as I know, WSH is party of IE. It is existing since Windows 98. The


lastest JScript is version5.8, please check the following link:

http://blogs.msdn.com/ie/archive/2009/03/24/what-s-new-in-jscript-for-ie8.as
px


Sincerely,

Vince Xu

Microsoft Online Support

On Tuesday, September 15, 2009 2:43 PM
Evertjan. wrote:

Vince Xu [MSFT] wrote on 14 sep 2009 inmicrosoft.public.scripting.
Vince Xu [MSFT] wrote on 14 sep 2009 in
microsoft.public.scripting.jscript:

Dear backup Vince,

This is usenet you are responding to the NG,
this is not email.

Please always quote on usenet.

Please repair your usenet signature,
start it with dash-dash-space-return.
[Your email signature should also conform to that, but that is OT here]


Interesting page, thanks.

See also:

<http://blogs.msdn.com/ie/archive/2009/01/13/responding-to-change-updated-
getter-setter-syntax-in-ie8-rc-1.aspx>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

On Sunday, December 06, 2009 4:46 AM
asdf wrote:

This is a multi-part message in MIME format.------=_NextPart_000_001B_01CA762F.
This is a multi-part message in MIME format.

------=_NextPart_000_001B_01CA762F.0B73F650
Content-Type: text/plain;
format=flowed;
charset="iso-8859-1";
reply-type=original
Content-Transfer-Encoding: 7bit

"not easy"


exonerate
v. acquit, absolve, clear of blame, declare innocent; relieve of an
obligation, free from a duty


Shakespeare ? Newton

Other shot the long bow for apples before that ?

All times are London ?

The British Pound the oldest "still' valid Paper fiat Currency ?

---------------------------------------------------------------------------------------------------

You are good !

Your time to reality is a little lagging though.

Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

------=_NextPart_000_001B_01CA762F.0B73F650
Content-Type: application/octet-stream;
name="IMG_TitleMenuOpen"
Content-Transfer-Encoding: base64
Content-ID: <A5F67583E439421191942C953810502A@client3>

R0lGODlhCQAGAIABAAE5cv7+/iH5BAEAAAEALAAAAAAJAAYAAAILjI+gC8edFHKzmgIAOw==

------=_NextPart_000_001B_01CA762F.0B73F650--


Submitted via EggHeadCafe - Software Developer Portal of Choice
Scrolling in WPF Toolkit?s Column Chart
http://www.eggheadcafe.com/tutorials/aspnet/0939d60c-8e17-4a27-b898-1fc772d2d6f6/scrolling-in-wpf-toolkits-column-chart.aspx

0 new messages