java - How do you print out a string exactly as it is? -
i had issue code because file path somehow ended "\n" @ end of path caused issues when trying use file, not able find file.
for debugging purposes, how can print out string including things \b \n \r etc.?
e.g.
system.out.println(file.getabsolutepath).withspecials()
which print console:
c:/folder/filename.extension\n
you try using code, escapes string. takes care of escapes except \u, should display fine anyway.
public static string escape(string str) { str = str.replace("\b", "\\b"); str = str.replace("\t", "\\t"); str = str.replace("\n", "\\n"); str = str.replace("\r", "\\r"); str = str.replace("\f", "\\f"); str = str.replace("\'", "\\'"); str = str.replace("\\", "\\\\"); return str; } this function can used follows:
system.out.println(escape("123\n\rabc"));
Comments
Post a Comment