How would you convert a String to a Java string literal?

Posted by Simon Nickerson on Stack Overflow See other posts from Stack Overflow or by Simon Nickerson
Published on 2010-03-16T09:36:44Z Indexed on 2010/03/16 9:56 UTC
Read the original article Hit count: 178

Filed under:
|

This is sort of the Java analogue of this question about C#.

Suppose I have a String object which I want to represent in code and I want to produce a string literal that maps to the same thing.

I was just about to write a state machine that ingests the string character by character and escapes appropriately, but then I wondered if there was a better way, or a library that provides a function to do this.

© Stack Overflow or respective owner

Related posts about java

Related posts about string