In my program I use for an import export functionality the delimiter ",". The problem for me that format numbers according to the country. For example, the decimal separator for UK is "." and grouping separator is "," and for Germany decimal separator is "," and grouping separator is ".".
So I have a problem during import with files that I export. There is a confusion with delimiter and number format with numbers which contains decimal separator or grouping separator ",".
There is my function during import
public static final String LINE_SEPERATOR = "\n";
public static final String DELIMITER = ",";
protected void writeEntry(final Writer writer, final EntryDTO entry) throws IOException {
final StringBuilder csvContent = new StringBuilder();
.append(StringEscapeUtils.escapeCsv(entry.getProduct().getName())).append(DELIMITER)
.append(StringEscapeUtils.escapeCsv(entry.getTotalWeight())).append(DELIMITER);
writer.write(csvContent.toString());
}
But during export when I split the line I'm receiving incorrect data due to confusion
final String[] attributes = line.split(delimiter);
Example of data when I import the file : UK Country
Name, Total Weight
example1 ,17,880 (This is grouping separator)
Germany country Name,Total Weight
Name, Total Weight
example2 , 17,88 (This is decimal separator)
I need a generic method that can handle these two cases without modifying the delimiter.
In input when splitting I have 3 values example1, 17, 88. But in my case I want just two values example1 and 17,880