Example usage for org.apache.commons.lang3 StringUtils replace

List of usage examples for org.apache.commons.lang3 StringUtils replace

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils replace.

Prototype

public static String replace(final String text, final String searchString, final String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

 StringUtils.replace(null, *, *)        = null StringUtils.replace("", *, *)          = "" StringUtils.replace("any", null, *)    = "any" StringUtils.replace("any", *, null)    = "any" StringUtils.replace("any", "", *)      = "any" StringUtils.replace("aba", "a", null)  = "aba" StringUtils.replace("aba", "a", "")    = "b" StringUtils.replace("aba", "a", "z")   = "zbz" 

Usage

From source file:fm.audiobox.core.utils.ModelUtil.java

/**
 * Performs models urls interpolation with the {@link fm.audiobox.core.utils.ModelUtil#TOKEN_PLACEHOLDER}.
 *
 * @param url   the url/*from ww w. j a  va  2s  .  c  om*/
 * @param token the token
 *
 * @return the computed url interpolation
 */
public static String interpolate(String url, String token) {
    return StringUtils.replace(url, TOKEN_PLACEHOLDER, token);
}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.EmailHelper.java

public static String handleUserIDToken(String originalText, User user) throws Exception {
    String ret = originalText;/*from  w w w. jav a2s  . co  m*/
    if (user == null || user.getUsername() == null) {
        throw new Exception("User or user id is null or empty.");
    }

    if (originalText != null) {
        ret = StringUtils.replace(originalText, Constants.EMAIL_USER_ID_TOKEN, user.getUsername());
    }

    return ret;
}

From source file:com.sk89q.craftbook.sponge.util.ParsingUtil.java

public static Vector3d parseUnsafeBlockLocation(String line)
        throws NumberFormatException, ArrayIndexOutOfBoundsException {
    line = StringUtils.replace(StringUtils.replace(StringUtils.replace(line, "!", ""), "^", ""), "&", "");
    double offsetX = 0, offsetY, offsetZ = 0;

    if (line.contains("="))
        line = RegexUtil.EQUALS_PATTERN.split(line)[1];
    String[] split = RegexUtil.COLON_PATTERN.split(line);
    if (split.length > 1) {
        offsetX = Double.parseDouble(split[0]);
        offsetY = Double.parseDouble(split[1]);
        offsetZ = Double.parseDouble(split[2]);
    } else//from  w w  w.ja  v a2s. co  m
        offsetY = Double.parseDouble(line);

    return new Vector3d(offsetX, offsetY, offsetZ);
}

From source file:de.micromata.genome.gwiki.utils.PropUtils.java

/**
 * Replaces ${} expressions./*from  w  w  w.  j ava  2 s  .c o  m*/
 * 
 * @param text
 * @param keyValues key and values at even and odd position.
 * @return
 */
public static String eval(String text, String... keyValues) {
    for (int i = 0; i < keyValues.length; ++i) {
        String search = "${" + keyValues[i] + "}";
        if (keyValues.length <= i + 1) {
            return text;
        }
        String repl = keyValues[++i];
        text = StringUtils.replace(text, search, repl);
    }
    return text;
}

From source file:dsd.controller.ParsedInputFilesController.java

public static String FetchStoredPath(eFileType fileType, Calendar date) {
    String pathForTransforming = ParsedInputFilesDAO.FetchStoredPath(fileType, date);
    pathForTransforming = StringUtils.replace(pathForTransforming, "\\", String.valueOf(File.separatorChar));
    pathForTransforming = StringUtils.replace(pathForTransforming, "/", String.valueOf(File.separatorChar));
    return pathForTransforming;
}

From source file:net.gtaun.wl.race.util.TrackUtils.java

public static String filterName(String name) {
    name = StringUtils.trimToEmpty(name);
    name = StringUtils.replace(name, "%", "#");
    name = StringUtils.replace(name, "\t", " ");
    name = StringUtils.replace(name, "\n", " ");
    return name;/*from  w  w  w .j a  va 2  s  .  c  o m*/
}

From source file:ch.cyberduck.core.LocaleFactory.java

/**
 * @param key   English variant/*  www  .ja v a  2s  . c om*/
 * @param table The identifier of the table to lookup the string in. Could be a file.
 * @return Localized from table
 */
public static String localizedString(final String key, final String table) {
    final String lookup = get().localize(key, table);
    if (StringUtils.contains(lookup, "{0}")) {
        return StringUtils.replace(lookup, "'", "''");
    }
    return lookup;
}

From source file:com.google.dart.java2dart.AbstractSemanticTest.java

protected static void printFormattedSource(ASTNode node) {
    String source = getFormattedSource(node);
    String[] lines = StringUtils.split(source, '\n');
    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];//from   w w w.  j  a va  2  s. c  om
        line = StringUtils.replace(line, "\"", "\\\"");
        System.out.print("\"");
        System.out.print(line);
        if (i != lines.length - 1) {
            System.out.println("\",");
        } else {
            System.out.println("\"");
        }
    }
}

From source file:com.eryansky.common.web.struts2.converter.DoubleConverter.java

@Override
public Object convertFromString(Map context, String[] values, Class toClass) {
    if (values != null && values.length > 0) {
        if (values[0].indexOf(',') != -1) {
            return Double.parseDouble(StringUtils.replace(values[0], ",", ""));
        } else {/*w  w w.  j ava  2s  . c om*/
            return Double.parseDouble(values[0]);
        }
    }
    return null;
}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.EmailHelper.java

public static String handleHostToken(String originalText, String host) {
    String ret = originalText;/*from   w  w w . j  a  v a  2 s. c o  m*/

    if (originalText != null) {
        ret = StringUtils.replace(originalText, Constants.EMAIL_WEB_HOST_TOKEN, host);
    }

    return ret;
}