Escapes a given entry. This escapes quotes (and detects commas that would require the line to be escaped). @param string The string to be escaped into its encoded state @return The escaped entry (with CSV quoting)
(String string)
| 39 | * @return The escaped entry (with CSV quoting) |
| 40 | */ |
| 41 | public static String escape(String string) |
| 42 | { |
| 43 | if (string.contains("\"") || string.contains(",")) |
| 44 | { |
| 45 | StringBuilder escaped = new StringBuilder(string.length() + 20); |
| 46 | escaped.append('"'); |
| 47 | escaped.append(string.replace("\"", "\"\"")); |
| 48 | escaped.append('"'); |
| 49 | return escaped.toString(); |
| 50 | } |
| 51 | return string; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Unescapes a given entry. This performs whitespace padding removal both |