Here you can find the source of toCodeString(String s)
Parameter | Description |
---|---|
s | a parameter |
public static String toCodeString(String s)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from www. ja v a 2 s. co m*/ * Given a string, returns a string that could be printed out in Java source * code. That is, all escapable characters are reversed. The returned string * will already be surrounded by quotes. * * @param s * @return */ public static String toCodeString(String s) { return "\"" + s.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\t", "\\t") + "\""; } }