开发者

read text from file containing escape characters to compile time equivalent

开发者 https://www.devze.com 2023-02-04 16:38 出处:网络
I would like to parse a text file or a java property which contains text such as: \"test\\n123\\t456\"

I would like to parse a text file or a java property which contains text such as: "test\n123\t456" to the equivalent if it were written in String test = "test\n123\t456";

i.e. I want the byte开发者_Python百科s to be the same when the text is read from a file compared to compiled in a java class.

I hope this makes sense,

-- Steven


Apache Commons have StringEscapeUtils.unescapeJava method.


In my IDE, if I paste into the middle of a string it turns tabs into \t and newlines into \n for you. I suggest you try that.

For example, if I paste

test
123
456

into a string it becomes

"test\n" +
"123\n" +
"456"
0

精彩评论

暂无评论...
验证码 换一张
取 消