Example usage for java.lang String replace

List of usage examples for java.lang String replace

Introduction

In this page you can find the example usage for java.lang String replace.

Prototype

public String replace(CharSequence target, CharSequence replacement) 

Source Link

Document

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

Usage

From source file:Main.java

public static String amount2String(String amount) {
    String temp = amount.replace(".", "").replace(",", "");
    return String.format("%012d", Long.parseLong(temp));
}

From source file:Main.java

/**
 * <p>//w  w  w .  j  ava2s . c o m
 * Escapes XML reserved characters to their corresponding XML-safe versions.
 * Specifically, this method:
 * </p>
 * <xmp> Replaces & with &amp; Replaces < with &lt; Replaces > with &gt;
 * </xmp>
 * 
 * @param txt
 *            Source string with text that needs to have XML characters
 *            escaped
 * @return String that has reserved XML characters escaped
 */
public static String escapeXMLText(String txt) {
    return txt.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
}

From source file:Main.java

public static String htmldecode(String str) {
    str = str.replace("&amp;", "&");
    str = str.replace("&nbsp;", " ");
    str = str.replace("&quot;", "\"");
    str = str.replace("&#39;", "'");
    str = str.replace("&lt;", "<");
    str = str.replace("&gt;", ">");
    str = str.replace("<br[^>]*>(?:(rn)|r|n)?", "n");
    return str;//  w  ww  .j  a  v  a  2  s  .  co  m
}

From source file:Main.java

private static String convertURI(String fileURL) {
    return fileURL.replace('\\', '/');
}

From source file:Main.java

private static String getClassFullName(String packagePath) {
    return packagePath.replace(File.separator, DOT).replace(EXT, BLANK_STR);
}

From source file:Main.java

/**
 * Unescape XML characters, and also replace our special token for preserving a carriage return followed by a line
 * feed.// w  w w. j  av  a 2  s  .c o m
 * 
 * @param body
 * @return
 */
public static String unescapeBody(String body) {
    body = body.replace("&lt;", "<");
    body = body.replace("&gt;", ">");
    body = body.replace("CARRIAGERETURN\n", "\r\n");
    return body;
}

From source file:Main.java

/**
 * Takes an escaped string, as generated by {@link XMLUtils#escapeData(String)} and returns its original form.
 * //from  w w w  .j a  va2 s  . c o  m
 * @param data escaped string as generated by {@link XMLUtils#escapeData(String)}, never null.
 * @return original, unescaped string, never null.
 */
public static String unEscapeData(String data) {
    data = data.replace("&lt;", "<");
    data = data.replace("&gt;", ">");
    data = data.replace("&amp;", "&");

    return data;
}

From source file:Main.java

public static final String escapeEntities(String s) {
    return s.replace("&", "&amp;").replace("<", "&lt;");//.replace(">", "&gt;");
}

From source file:Main.java

public static Long longFromString(String s) {
    s = s.replace(",", "").replace(".", "").replace(" ", "");
    try {//  w ww . jav a 2  s  .  c om
        return Long.valueOf(s);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0l;
}

From source file:Main.java

public static String modifyHtmlQuote(String body) {
    return Html.fromHtml(body.replace("\n", "<br/>")).toString();
}