Example usage for java.lang String replaceAll

List of usage examples for java.lang String replaceAll

Introduction

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

Prototype

public String replaceAll(String regex, String replacement) 

Source Link

Document

Replaces each substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:Main.java

public static String URLEncode(String url) {

    url = url.replaceAll("%", "%25");
    url = url.replaceAll(" ", "%20");
    url = url.replaceAll("&", "%26");
    url = url.replaceAll("<", "%3c");
    url = url.replaceAll(">", "%3e");

    if (url.indexOf('^') >= 0) {
        url = url.replaceAll("^", "%22"); // 5e
    }//from   w  ww. j  a v a  2 s .c om

    url = url.replaceAll("'", "%27");
    url = url.replaceAll("\"", "%22");
    url = url.replaceAll(",", "%2c");
    url = url.replaceAll(":", "%3a");

    if ((url.indexOf('{') >= 0) || (url.indexOf('}') >= 0) || (url.indexOf('\\') >= 0)
            || (url.indexOf('|') >= 0) || url.indexOf('^') >= 0 || (url.indexOf('`') >= 0)) {
        url = null;
        return url;
    }
    return url;
}

From source file:Main.java

public static String removeHtml(String htmlStr) {
    if (TextUtils.isEmpty(htmlStr)) {
        return "";
    }//from w  w w .j  ava 2 s  . c om
    String html = htmlStr;
    html = html.replaceAll("<(.*?)\\>", " ");//Removes all items in brackets
    html = html.replaceAll("<(.*?)\\\n", " ");//Must be undeneath
    html = html.replaceFirst("(.*?)\\>", " ");//Removes any connected item to the last bracket
    html = html.replaceAll("&nbsp;", " ");
    html = html.replaceAll("&amp;", "&");
    html = html.replaceAll("&lt;", "<");
    html = html.replaceAll("&gt;", ">");
    html = html.replaceAll("&nbsp;", " ");
    return html;
}

From source file:Main.java

public static String formatModel(String model) {
    return model == null ? null
            : model.replaceAll("\\+", "plus").replaceAll("[^a-zA-Z0-9]", "").trim().toLowerCase();
}

From source file:Main.java

public static String removeEmptyCharacters(String text) {
    if (text != null) {
        text = text.replaceAll("\\s*", "");
    } else {/*from  ww  w  . ja v  a2  s  . c  om*/
        text = "";
    }
    return text;
}

From source file:Main.java

public static String getCurrentNumberString(String string) {
    String Current = string.replaceAll(" ", "");
    char[] chars = Current.toCharArray();
    String number = "";
    for (int i = 8; i < chars.length - 6; i++) {
        number += chars[i];/*from   w  ww  .j av a  2  s  .  c  om*/
    }
    return toStringHex1(number);
}

From source file:Main.java

public static String decodeXML(final String xML) {

    String result = xML.replaceAll(LT_A, LT);
    result = result.replaceAll(GT_A, GT);
    result = result.replaceAll(QUOTE_A, QUOTE);
    result = result.replaceAll(APOS_A, APOS);
    result = result.replaceAll(AND_A, AND);
    result = result.replaceAll(NBSP_A, SPACE);
    return result;
}

From source file:Main.java

public static String clearXSSMinimum(String value) {
    if (value == null || value.trim().equals("")) {
        return "";
    }//from  w ww . j  a  va 2s. co m

    String returnValue = value;

    returnValue = returnValue.replaceAll("&", "&amp;");
    returnValue = returnValue.replaceAll("<", "&lt;");
    returnValue = returnValue.replaceAll(">", "&gt;");
    returnValue = returnValue.replaceAll("\"", "&#34;");
    returnValue = returnValue.replaceAll("\'", "&#39;");
    return returnValue;
}

From source file:Main.java

/**
 * //w ww  .  j a v a 2 s .c  o  m
 * @param nombreNuevo
 * @param nombreViejo
 * @param documento
 * @return
 */
public static String renombraEtiqueta(String nombreNuevo, String nombreViejo, String documento) {

    documento = documento.replaceAll("<" + nombreViejo + ">", "<" + nombreNuevo + ">");
    documento = documento.replaceAll("</" + nombreViejo + ">", "</" + nombreNuevo + ">");
    documento = documento.replaceAll("<" + nombreViejo + "/>", "<" + nombreNuevo + ">");
    return documento;
}

From source file:Main.java

public static String replaceCode_eq_se(String text) {
    text = null == text ? "" : text;
    return text.replaceAll("=", "{eq}").replaceAll(";", "{se}");
}

From source file:Main.java

public static int getLayoutIdFromName(Context context, String type, String name) {
    String layoutName = type + "_" + name.replaceAll("(.)(\\p{Lu})", "$1_$2").toLowerCase();
    try {/*from   w  ww  . j  av a 2  s  .  co  m*/
        return context.getResources().getIdentifier(layoutName, "layout", context.getPackageName());
    } catch (Exception ex) {
        Log.e("Yintro", "Please create layout suggested name: " + layoutName);
        return -1;
    }
}