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) == ',')
String ordSplit = ord.split(",");
System.out.println("delims: " + ordSplit.length + " commas: " + commas + " "+ ordSplit + " " + ordSplit + " " + ordSplit + " " + ordSplit);
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)
For this particular string, ordSplit.length = 24 and commas = 26.
Any help is appreciated. Thank you.