java - Character to String representation -
I need to find special escape java characters (\ n, \ t, \ b, etc.) in the groove of strings and Then what are the special characters in the printed strings, so, when I want to print, I would like to change the character value for "\ n", "\ t" and "\ n" for the string like "\ n" . I did this with a switch statement for all the characters of this type. I wonder if there is a solution in which every one does not include the investigation.
A library is not found, but on the other hand, my quick implementation does not look too horrible - I like it on a RegExp too;)
public string unscape (strings) {stringbilder result = new Stringbuilder (); For (four c: s.toCharArray ()) {result.append (toLiteral (c)); } Return Results. } Private string tooltail (four c) {switch (c) {case '\ n': return "\\ n"; Case '\ t': return "\\ t"; Case '\ r': return "\\ r"; Case '\ f': return "\\ f"; Case '\ b': return "\\ b"; Case '\' ": return" \ '"' '; Case '\ "': return" \\\ ""; Case '\\': return "\\\\"; Default: Return c; }}
According to my compiler, researchers are all escape sequences that are allowed for strings.
Comments
Post a Comment