Java tutorial
//package com.java2s; public class Main { private static final char TS_DEFAULT = ' '; private static final char CS_DEFAULT = ','; private static final char TS_WKT = ','; private static final char CS_WKT = ' '; /** * Converts the seperators of the coords to the WKT from ts and cs * * @param coords the coords string to convert * @param ts the separator that separates 2 coordinates * @param cs the separator between 2 numbers in a coordinate */ public static String toWktCoords(Object coords, Object ts, Object cs) { String coordsString = coords.toString(); char tsString; if (ts == null || ts.toString().length() == 0) { tsString = TS_DEFAULT; } else { tsString = ts.toString().charAt(0); } char csString; if (cs == null || cs.toString().length() == 0) { csString = CS_DEFAULT; } else { csString = cs.toString().charAt(0); } if (tsString == TS_WKT && csString == CS_WKT) { return coordsString; } if (tsString == CS_WKT) { tsString = ';'; coordsString = coordsString.replace(CS_WKT, tsString); } coordsString = coordsString.replace(csString, CS_WKT); String result = coordsString.replace(tsString, TS_WKT); char lastChar = result.charAt(result.length() - 1); if (result.charAt(result.length() - 1) == TS_WKT || lastChar == CS_WKT) { result = result.substring(0, result.length() - 1); } return result; } /** * Replace the pattern with the substitution */ public static String replace(Object src, Object pattern, Object substitution) { String result = src.toString().replaceAll(pattern.toString(), substitution.toString()); return result; } }