Hello,
I have been running a program for months now that I wrote that splits strings and evaluates the resulting split. I have a field only object (OrderDetail) that the values in the resulting array of strings from the split holds.Today, I was getting an array out of bounds exception on a split. I have not changed the code and from I can tell the structure of the message has not changed. The string is comma delimited. When I count the commas there are 26, which is expected, however, the split is not coming up with the same number.
Here is the code I used and the counter I created to count the commas:
public OrderDetail stringParse(String ord)
{
OrderDetail returnOD = new OrderDetail();
int commas = 0;
for( int i=0; i < ord.length(); i++ )
{
if(ord.charAt(i) == ',')
{
commas++;
}
}
String[] ordSplit = ord.split(",");
System.out.println("delims: " + ordSplit.length + " commas: " + commas + " "+ ordSplit[0] + " " + ordSplit[1] + " " + ordSplit[2] + " " + ordSplit[5]);
........
}
The rest of the method just assigns values to fields OrderDetail returnOD.
Here is the offending string (XXX's replace characters to hide private info)
1096200000000242505,1079300000007578558,,,2013.10.01T23:58:49.515,,USD/JPY,Maker,XXX.XX,XXX.XXXXX,XXXXXXXXXXXXXXXX,USD,Sell,FillOrKill,400000.00,Request,,,97.7190000,,,,,1096200000000242505,,,
For this particular string, ordSplit.length = 24 and commas = 26.
Any help is appreciated. Thank you.