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 getPowerNumberString(String string) {
    String Current = string.replaceAll(" ", "");

    char[] chars = Current.toCharArray();
    String number = "";
    for (int i = 8; i < chars.length - 4; i++) {
        number += chars[i];//from   w w  w. j  a  v  a  2  s  . co  m
    }
    return number;
}

From source file:Main.java

public static String xmlEncode(String str) {
    return str.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll("<", "&gt;")
            .replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
}

From source file:Main.java

/**
 * Toglie placeholder e spazi all'inizio e alla fine.
 *
 * @param s valore da normalizzare/*from   w w  w. j a v  a 2  s .c  o  m*/
 * @return valore normalizzato
 */
public static String normalize(String s) {
    String s1 = s.replaceAll("_*$", "");
    return s1.trim();
}

From source file:Main.java

/**
 * Converts a XHTML compliant id (used in jspx) to a CSS3 selector spec compliant id. In that
 * it will replace all '.,:,-' to '_'//ww w  .  ja  va 2s.c  o m
 * 
 * @param proposed Id
 * @return cleaned up Id
 */
public static String convertId(String proposed) {
    return proposed.replaceAll("[:\\.-]", "_");
}

From source file:Main.java

public static String unescapeXml(String str) {
    str = str.replaceAll("&amp;", "&");
    str = str.replaceAll("&lt;", "<");
    str = str.replaceAll("&gt;", ">");
    str = str.replaceAll("&quot;", "\"");
    str = str.replaceAll("&apos;", "'");
    return str;//from ww w  .  j  a  va2  s  .  c  om
}

From source file:Main.java

public static String decodeApostrophes(String value) {
    value = value.replaceAll("&#39;", "'");
    value = value.replaceAll("&#x27;", "'");
    value = value.replaceAll("&apos;", "'");

    return value;
}

From source file:Main.java

public static int getWordCount(String content) {
    String text = Html.fromHtml(content.replaceAll("<img[^>]*>", "")).toString();
    return text.split("\\s+").length;
}

From source file:Main.java

public static String removeLeadingZeroes(String num) {
    String regex = "^0*";
    return num.replaceAll(regex, "");
}

From source file:Main.java

public static String deleteSpecialCharactersInString(String stringToAdapt) {
    return stringToAdapt.replaceAll("[\"*/:<>?\\\\|]", "");
}

From source file:Main.java

/**
 * <p>Effectively un-escapes a string, performs the reverse of {@link #escapeString(String)}.</p>
 *
 * @param text//from w  w  w.  jav a 2s .  c o  m
 * @return {@link String}
 */
public static String unescapeString(String text) {
    String unescaped = text.replaceAll("\\\\n", "\n");
    unescaped = unescaped.replaceAll("\\\\N", "\n");
    unescaped = unescaped.replaceAll("\\\\\\\\", "\\\\");
    unescaped = unescaped.replaceAll("\\\\,", ",");
    unescaped = unescaped.replaceAll("\\\\;", ";");
    unescaped = unescaped.replaceAll("\\\\:", ":");
    return unescaped;
}