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 unescapeXML(String xml) {
    // TODO: this is incorrect and inefficient
    return xml.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&");
}

From source file:Main.java

public static String escapeRegexp(String s) {
    String[] esc = { "\\", ".", "*", "[", "]", "(", ")", "|", "?", "$", "^" };
    String result = s;
    for (String escChar : esc)
        result = result.replace(escChar, "\\" + escChar);
    return result;
}

From source file:Main.java

public static Bundle parseUrl(String url) {
    url = url.replace("#", "?");
    try {//www . j a v  a 2s .c o  m
        URL u = new URL(url);
        Bundle b = decodeUrl(u.getQuery());
        Bundle ref = decodeUrl(u.getRef());
        if (ref != null)
            b.putAll(ref);
        return b;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

public static String deparseText(String text) {
    if (text.contains(TAG_OPEN)) {
        return text.replace(TAG_OPEN, "").replace(TAG_CLOSE, "");
    }/*from  w ww. j av  a 2 s.  c om*/

    return text;
}

From source file:Main.java

public static String formatPhoneNumber(String phone) {

    if (phone != null) {
        phone = phone.replace("+", "00");
        phone = phone.replaceAll("[^\\d]", "");
        phone = phone.replace(" ", "");
    } else {//  w w w  . ja  v a  2  s . c o  m
        phone = "";
    }

    return phone;
}

From source file:Main.java

public static String escapeAttribute(String attribute, boolean escapeEntities) {
    if (attribute == null)
        return "";
    String ret = attribute;
    if (escapeEntities)
        ret = ret.replace("&", "&amp;");
    return ret.replace("\"", "&#34;").replace("'", "&#39;");
}

From source file:Main.java

public static String toIdableName(String xpath) {
    xpath = "X" + xpath;
    xpath = xpath.replace("/", "-");
    xpath = xpath.replace("[", "_");
    return xpath.replace("]", ":");
}

From source file:Main.java

public static String utf8Replace(String str) {
    if (str != null) {
        return str.replace(FULL_MINUS, HALF_MINUS);
    }/*from w  ww.ja va  2 s .  c o  m*/
    return null;
}

From source file:Main.java

public static String escapeElementContent(String xmlContent, boolean escapeEntities) {
    if (xmlContent == null)
        return "";
    String ret = xmlContent;
    if (escapeEntities)
        ret = ret.replace("&", "&amp;");
    return ret.replace("<", "&lt;"); // There's no need to escape '>'.
}

From source file:Main.java

public static String getAsAttribute(String attrName, String value) {
    if (value != null) {
        String val = value.replace("&", "&amp;");
        //val = val.replace("\"", "&quot;");
        val = val.replace("\"", "&apos;");
        val = val.replace("<", "&lt;").replace(">", "&gt;");
        return " " + attrName + "=\"" + val + "\" ";
    } else {/*w w w.j  a v a2  s . c  om*/
        return " " + attrName + "=\"\" ";
    }
}