Splitting a Comma Separated String - Issue with Trailing Blanks
807589Jul 23 2008 — edited Jul 23 2008Thanks for checking out my post:
I have a String which is read off a CSV:
000001,S,LM,18.900,07/13/2007,07/17/20087ICR42,,,,6,,,,D,,,OH,,,,212,200,,,15:42:18,,,,,
I am attempting to create individual values that I can access via split:
String as[] = s5.split(",");
My intuition says should create an array of length 29 given the number of commas in the String. When I take a look at the created array, however, the length is 26. It appears that, while blank fields (where there are two commas with no value in between) are generally handled correctly by the split, the five remaining commas are stripped! Thus, the resulting array ends with the value '15:42:18'.
I've output the array:
length 26
0: 000001 1: S 2: LM 3: 18.900 4: 07/13/2007 5: 07/17/2007 6: ICR42 7: 8: 9: 10: 6 11: 12: 13: 14: D 15 16: 17: OH 18: 19: 20: 21: 212 22: 200 23: 24: 25: 15:42:18
I'm wondering why on earth the trailing commas are being completely stripped out of the array, and if I'd be able to write an appropriate expression to create the array I am looking for.
Thanks much for your help,
James