I have a method that looks like this:
public static String escape(String text)
{
String r = replace(text, "\\", "\\\\");
r = replace(r, "\r", "\\r");
r = replace(r, "\b", "\\b");
r = replace(r, "\t", "\\t");
r = replace(r, "\n", "\\n");
r = replace(r, "\f", "\\f");
return r;
}
Is there a faster, less brutal way to do this and if so what would that way look like?
Note that this is J2ME, so no Apache commons, and no regex.