I have a string in the following pattern.
"xxx","xx",12.12.2011,16,"remarks"
I am parsing this string and writing to a database. I have written the code. But however I try, I am not able to succeed with double quote extraction. I want eliminate the Quotes when writing to database. My code is given below.
This is the final code trying the regular expressions.int asciiquote=34; // Ascii value for " int asciichar=0; String dateregex = "(0?[1-9]|[12][0-9]|3[01]).(0?[1-9]|1[012]).((19|20)\\d\\d)"; Pattern pat; Matcher mat; pat=Pattern.compile(dateregex); String fldvals[]=new String[7]; InputStream fstream = fil.getInputStream(); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { // Validate String System.out.println(strLine); ++maxline; i=0; errors=false; errmsg=""; StringTokenizer st = new StringTokenizer(strLine,","); while(st.hasMoreTokens()) { fldvals[i]=st.nextToken(); i++; } //now convert the values to uppercase after removing the " if any for (i=0; i<fldvals.length; i++) { asciichar = Integer.parseInt(fldvals[i].substring(0,1)); if (asciichar==asciiquote) { fldvals[i]=fldvals[i].substring(1,(fldvals[i].length()-1)); fldvals[i]=fldvals[i].toUpperCase(); fldvals[i]=fldvals[i].trim(); } else if (pat.matches(dateregex, fldvals[i])) { fldvals[i]=fldvals[i].replace(".", "/"); // replace "." in date with "/" } }
I'm getting "java.lang.NumberFormatException: For input string: """
What's going wrong?