How to deal with extra space characters while Reading a CSV file?
- by Ravi Dutt
I am reading a CSV file with CSV Open Source API. as shown below:
Java Code:-->
CSVReader reader = new CSVReader(new FileReader(filePath),'\n');
String[] values;
if((read=(reader.readNext()))!=null)
{
values = (read[0].split(" (?=([^\"]*\"[^\"]*\")*[^\"]*$)",-1)).length;
}
// code ends here
When I read this CSV file line by line and split that line with delimiter. Then after spliting values each value I get contains extra space character after each character in String. Suppose value in file is like "ABC" and I got this after reading from CSV file reader as " A B C " . I used removeAll("\s+","") on each value even after it is not working. Thank You in Advance.