Here you can find the source of toJavaString(String text)
Parameter | Description |
---|---|
text | a parameter |
public static String toJavaString(String text)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2014 IBM Corp.// w ww. ja v a 2 s . co m * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. * * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * *******************************************************************************/ public class Main { /** * @param text * @return a Java string */ public static String toJavaString(String text) { String string = text; if (string != null) { string = string.replaceAll("\n", "\\\\n"); string = string.replaceAll("\r", "\\\\r"); string = string.replaceAll("\"", "\\\\\""); } StringBuilder sb = new StringBuilder(); sb.append("\""); sb.append(string); sb.append("\""); return sb.toString(); } }