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 violent way to do this, and if so, what would it look like?
Note that this is J2ME, so there is no Apache and no regular expression.
source
share