Jscript String.split on csv file, Ignores leading empty fields -


hey guys need figuring out how write jscript includes empty fields separated commas @ beginning , puts them in array.

temp = new array; string = ",,field3,field4,,field6"; temp = string.split(regexp, -1); 

i have regexp pick out commas. know split ignores empty fields. need fields since working reading csv file. need array contain empty strings there empty data field.

what want

temp[0] = "", temp[1] = "", temp[3] = field 3

what is

temp[0] = field3

like that, ideas or workarounds?

the workaround jscript's rather peculiar behavior* use string (not regexp) separator:

var s = ",,field3,field4,,field6"; var = s.split(","); wscript.echo("a:", a.length, "[" + a.join(",") + "]"); var b = s.split(/,{1,1}/); wscript.echo("b:", b.length, "[" + b.join(",") + "]"); 

output:

cscript 30603770.js a: 6 [,,field3,field4,,field6] b: 3 [field3,field4,field6] 

(*) @ least 1 other javascript implementation behaves should:

rhino 1.7 release 5 prerelease 2013 07 16 js> var s = ",,field3,field4,,field6"; js> var = s.split(","); js> print("a:", a.length, "[" + a.join(",") + "]"); a: 6 [,,field3,field4,,field6] js> var b = s.split(/,/); js> print("b:", b.length, "[" + b.join(",") + "]"); b: 6 [,,field3,field4,,field6] 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -