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 reserved XML characters with escapes
 * //from w  ww  .  j  a va  2s.c om
 * @param input
 *            a String to process
 * @return the same String but with reserved XML characters escaped
 */
static public String escapeCharacters(String input) {
    if (input == null)
        return input;
    input.replace("&", "&");
    input.replace("<", "&lt;");
    input.replace(">", "&gt;");
    input.replace("\"", "&quot;");
    input.replace("'", "&apos;");
    return input;
}

From source file:Main.java

public static String replaceStringSpaceToUnderScore(String str) {
    if (str == null || str.length() == 0) {
        return "";
    }//ww  w . j  a va 2s .c  om
    return str.replace(" ", "_");
}

From source file:Main.java

public static String changeImageUrl(String imageUrl, String oldDimension, String newDimension) {
    String tempImageUrl;// ww  w. j  av  a2s .  co  m
    tempImageUrl = imageUrl.replace(oldDimension, newDimension);
    return tempImageUrl;
}

From source file:Main.java

public static String shortenUrl(String url) {
    if (url == null) {
        return null;
    }/*  w w  w.  j a  v  a  2  s  . co  m*/
    return url.replace("http://", "").replace("https://", "")
            .replace("vmkrcmar21.informatik.tu-muenchen.de/wordpress/", "").replace("cms.integreat-app.de/", "")
            .replace("/", "");
}

From source file:Main.java

/**
 * Gets name./*  w  w  w.  j a v  a  2s  .  c o m*/
 *
 * @param pathOrUrl the path or url
 * @param useHash   the use hash
 * @return the name
 */
public static String getName(String pathOrUrl, boolean useHash) {
    if (useHash) {
        return pathOrUrl.replace("/", "_") + "." + getExtension(pathOrUrl);
    }
    int pos = pathOrUrl.lastIndexOf('/');
    if (0 <= pos) {
        return pathOrUrl.substring(pos + 1);
    } else {
        return String.valueOf(System.currentTimeMillis()) + "." + getExtension(pathOrUrl);
    }
}

From source file:org.trustedanalytics.hadoop.admin.tools.HadoopClientParamsImporter.java

static String escapeCharacters(String string) {
    return string.replace(SpecialCharacter.DOLLAR.getCharacter(),
            SpecialCharacter.DOLLAR.getEscapedCharacter());
}

From source file:com.github.bjoern2.codegen.util.LicenseUtils.java

public static String apache2(int year, String owner) {
    String template = loadTemplate("apache-2.0.txt");
    template = template.replace("[yyyy]", "" + year);
    template = template.replace("[name of copyright owner]", owner);
    return template;
}

From source file:Main.java

public static String classNameForPath(String classPath) {
    String className = classPath.substring(0, classPath.length() - ".class".length());
    return className.replace(File.separatorChar, '.');
}

From source file:Main.java

public static String format(String src, Object... objects) {
    int k = 0;/*from w w w . j a  va 2 s  .c  om*/
    for (Object obj : objects) {
        src = src.replace("{" + k + "}", obj.toString());
        k++;
    }
    return src;
}

From source file:io.apiman.test.policies.EchoBackEndApi.java

/**
 * Normalize newlines across platforms./*from   ww  w .  jav a  2 s . c  o m*/
 * @param output
 */
private static String normalize(String output) {
    return output.replace("\r\n", "\n");
}