Java escape characters in strings - string contains \r (need to keep "r") -
i have string "ead\rgonzalez" passed me.
need pull out "rgonzalez" it.
running problems "\" character.
cannot find index of it, cannot replace it, etc.
on pulling data after "\" appreciated.
string receive in format of domain\username; data can vary.
another example us\ngross \n interpreted newline character.
to clarify, not adding '\', trying split string on '\'
this string contains '\r' in character, special one.
need way make \r contained within string 2 separate characters, '\' , 'r'.
you haven't provided code, i'm assuming you're doing this:
string user = request.getparameter("user"); // user = "ead\rgonzalez"
if declare static string in application, have escape backslash because special character java strings:
string user = "ead\\rgonzalez";
to split string on backslash must escape twice in regex pass split
method. once because backslash special character java strings , again because backslash special character regex strings. instead of 1 backlash have four. 1 escaped have two, , both of them escaped again.
string[] parts = user.split("\\\\");
now have split string:
system.out.println(parts[0]); // "ead" system.out.println(parts[1]); // "rgonzalez"
Comments
Post a Comment