Hi! I m reading from a txt file. I tried many different ways but it's not working. I've problem w/ reading the following line: prompt this "hello how r u", '"fine"', "'thanku,'" ; but ignore this
I want to get different tokens like: prompt this hello how r u "fine" 'thanku'
Want to ignore the rest of the line starting with semicolon and want to store 'em in array. The code I m using is:
while ( (line = infile.readLine()) != null ) {
StringTokenizer st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
String s = st.nextToken();
if (s.startsWith(";")) continue;
if(s.endsWith(",")) s = s.replace(',', ' ');
if(s.charAt(0) == '"') {
while ((s.charAt(s.length() - 1) != '"')) {
s += " " + st.nextToken();
}
s = s.substring(1, s.length() - 1);
}
System.out.println(s);
}
I get: prompt this hello how r u", '"fine"', "'thanku,' ignore
And if I return ","(comma) as a delimiter in the StringTokenizer, then I get: prompt this "hello how r u" '"fine"' "'thanku '" ; ignore
I tried it many ways but it doesn't work. Also I've no idea how to get these tokens and store them in array. Pls help! I really appreciate ur help. Thanks in advance.