java - Print a string with unformatted characters ("\t" instead of a tab) -


i reading string of text source cannot see otherwise. see actual formatting codes such as: \t \n etc. instead of actual tabs , newline

when print string using system.out.println, see tabs visually , have count them highlight mouse.

i've tried using regex replace \t in string \\t have little experience regex i'm not sure if expression correct. here's have:

string text = extractor.gettext(); text.replaceall("\n", "\\n"); 

i appreciate alternate method of doing without regex if possible. i'm using xssfexcelextractor if makes difference.

you can try using stringescapeutils apache commons if want see characters java convert

string s="\r\t\n abc"; system.out.println(stringescapeutils.escapejava(s)); 

output

\r\t\n abc 

in case want escape \t or \n can use

string escaped = origina.replace("\t","\\t").replace("\n","\\n)"` 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -