Re: CSV and regex s.split(",") and empty fields
- From: Gerry Hickman <gerry666uk2@xxxxxxxxxxxxxxxx>
- Date: Wed, 02 Sep 2009 21:44:31 +0100
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.
X-Tomcat-NG: microsoft.public.scripting.jscriptdelimiters
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,within quotes, empty fields, non-quoted fields, and leading/trailling delimiters, I believe the code examples I posted on the 30th Aug 09 arethebest solution I've seen so far.http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
Thanks.
--
Gerry Hickman
London (UK)
"Thomas Sun [MSFT]" <v-thsun@xxxxxxxxxxxxxxxxxxxx> wrote in message news:RLMd82hKKHA.4732@xxxxxxxxxxxxxxxxxxxxxxxxxHi 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
opposedications.
With newsgroups, MSDN subscribers enjoy unlimited, free support asto 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 wrote:this.charAt(J) }
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 +=
at?if (S>"") A.push(S)Thanks. This works, but perhaps would fall over with more complex
return A }
X = t.Split().join("+") // one+two++four+++seven+eight
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--
Gerry Hickman (London UK)
--
Gerry Hickman (London UK)
.
- Follow-Ups:
- Re: CSV and regex s.split(",") and empty fields
- From: Evertjan.
- Re: CSV and regex s.split(",") and empty fields
- References:
- Re: CSV and regex s.split(",") and empty fields
- From: Gerry Hickman
- Re: CSV and regex s.split(",") and empty fields
- From: Thomas Sun [MSFT]
- Re: CSV and regex s.split(",") and empty fields
- Prev by Date: Re: CSV and regex s.split(",") and empty fields
- Next by Date: Re: CSV and regex s.split(",") and empty fields
- Previous by thread: Re: CSV and regex s.split(",") and empty fields
- Next by thread: Re: CSV and regex s.split(",") and empty fields
- Index(es):
Relevant Pages
|