DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Katarina has posted 8 posts at DZone. View Full User Profile

Escape Double Quotes In String

11.19.2010
| 3232 views |
  • submit to reddit
        // Escape double quotes in string

	private String escapeDoubleQuotes(String fileString) {
		StringBuilder escaped = new StringBuilder();
		for (int i = 0; i < fileString.length(); i++) {
			fileString.toCharArray();
			char ch = fileString.charAt(i);
			if (ch == 34) {
				escaped.append((char) 92);
			}
			escaped.append(ch);
		}
		return escaped.toString();
	}