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

/**
 * Replaces all <tt>'>'</tt> characters with <tt>'&gt;'</tt>
 * @param aString//from   w w w .j ava2  s  .co m
 * @return
 */
private static String escapeGreaterThanSigns(String aString) {
    return aString.replace(">", "&" + PREDEFINED_ENTITY_GREATERTHAN_SIGN + ";");
}

From source file:Main.java

/**
 * Replaces all <tt>'\''</tt> characters with <tt>'&apos;'</tt>
 * @param aString//from w w w  . j  a  va2 s.  c o  m
 * @return
 */
private static String escapeApostrophes(String aString) {
    return aString.replace("'", "&" + PREDEFINED_ENTITY_APOSTROPHE + ";");
}

From source file:Main.java

public static String convertToXMLString(String instr) {
    //XML has a special set of characters that cannot be used in normal XML strings
    String ourstr = instr;
    ourstr = ourstr.replace("&", "&amp;");
    ourstr = ourstr.replace("<", "&lt;");
    ourstr = ourstr.replace(">", "&gt;");
    ourstr = ourstr.replace("\"", "&quot;");
    ourstr = ourstr.replace("'", "&#39;");

    return ourstr;
}

From source file:Main.java

/**
 * Replaces all <tt>'&'</tt> characters with <tt>'&amp;'</tt>
 * @param aString/* w w  w . java  2  s.  c  o  m*/
 * @return
 */
private static String escapeAmpersands(String aString) {
    return aString.replace("&", "&" + PREDEFINED_ENTITY_AMPERSAND + ";");
}

From source file:Main.java

/**
 * The method parseRuby converts kanji enclosed in ruby tags to the
 * format which is supported by the textview {Kanji:furigana}
 *
 * @param textWithRuby/*from w w  w .j a  v a2  s. com*/
 */
public static String parseRuby(String textWithRuby) {
    String parsed = textWithRuby.replace("<ruby>", "{");
    parsed = parsed.replace("<rt>", ";");
    parsed = parsed.replace("</rt>", "");

    return parsed.replace("</ruby>", "}");
}

From source file:Main.java

private static String escapeHTML(final String content) {
    String escaped = content.replace("&", "&amp;");
    escaped = escaped.replace("<", "&lt;");
    escaped = escaped.replace(">", "&gt;");
    escaped = escaped.replace("\r\n", "\n");
    escaped = escaped.replace("\r", "\n");
    escaped = escaped.replace("\n", "<br/>");
    return escaped;
}

From source file:Main.java

/**
 * Decode specials chars for XML representation
 * /*from w  w  w  .  j a v  a2s . c  o m*/
 * @param pi_text The encoded text
 * @return The decoded text
 */
public static String Decode(String pi_text) {
    pi_text = pi_text.replace("&amp;", "&");
    pi_text = pi_text.replace("&apos;", "'");
    return pi_text;
}

From source file:Main.java

/**
 * To html./*from  w ww.j  av a  2 s.  c  om*/
 * 
 * @param src
 *            the src
 * @return the string
 */
public static String ToHtml(String src) {
    src = src.replace("\r\n", "<br>");
    src = src.replace("\n", "<br>");
    src = src.replace("\r", "<br>");
    src = src.replace(" ", "&nbsp;");
    ToJavascriptText(src);
    return src;
}

From source file:Main.java

private static String __htmlTextToPlainText(String text) {
    text = text.replace("<", "&lt;");
    text = text.replace(">", "&gt;");
    return text;/*from   ww w .  ja  v  a 2 s  .c o m*/
}

From source file:Main.java

public static String getProjectRelativeRelativePath(String path, String buildDir) {
    path = path.replace('\\', '/');
    buildDir = buildDir.replace('\\', '/');
    int indexOfBuildDir = path.indexOf(buildDir);
    if (indexOfBuildDir == 0) {
        path = path.substring(buildDir.length());
    }//w  ww .  ja va 2s .com
    if (path.startsWith("/")) {
        return path.substring(1);
    }
    return path;
}