Here you can find the source of quoteJavaString(String s)
Parameter | Description |
---|---|
s | Unquoted literal |
public static String quoteJavaString(String s)
//package com.java2s; /*/* w w w . jav a 2s. co m*/ // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // // Copyright (C) 2001-2005 Julian Hyde // Copyright (C) 2005-2012 Pentaho and others // All Rights Reserved. */ public class Main { /** * Quotes a string literal for Java or JavaScript. * * @param s Unquoted literal * @return Quoted string literal */ public static String quoteJavaString(String s) { return s == null ? "null" : "\"" + s.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\"") + "\""; } }