I am using the below code to find the nth occurrence of ,
(comma) in the string. And once I get this, I need to get the value between this occurrence(nth) and next occurrence (n+1th occurrence)
Please let me know if I am going wrong somewhere.
int ine=nthOccurence(line,18);
String strErrorCode=line.substring(ine,line.indexOf(",", ine+1));
String errorCode=strErrorCode.substring(1, strErrorCode.length());
The function
public static int nthOccurence(String strLine,int index)
{
char c=',';
int pos = strLine.indexOf(c, index);
while (index-- > 0 && pos != -1)
{
pos = strLine.indexOf(c, pos+1);
// System.out.println("position is " + pos);
}
return pos;
}
Thanks.