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:com.nicohuysamen.fetchapp.RequestConstants.java

public static String generateRequestUrl(final String method) {
    return StringUtils.replace(BASE_URL, TOKEN_METHOD, method);
}

From source file:de.vandermeer.skb.interfaces.transformers.textformat.Test_Text_To_WrappedFormat.java

@Test
public void test_Simple() {
    String words = new LoremIpsum().getWords(30);
    String text = words;/*from   w  w  w . j av a2  s.  c  om*/
    text = StringUtils.replace(words, "dolor ", "dolor " + LINEBREAK);
    text = StringUtils.replace(text, "dolore ", "dolore " + LINEBREAK);

    Pair<ArrayList<String>, ArrayList<String>> textPair;

    textPair = Text_To_WrappedFormat.convert(text, 20, null);
    assertEquals(0, textPair.getLeft().size());
    assertEquals(11, textPair.getRight().size());
    assertEquals(words, StringUtils.join(textPair.getRight(), ' '));

    textPair = Text_To_WrappedFormat.convert(text, 30, Pair.of(6, 10));

    System.err.println(words);
    System.err.println(text);
    System.err.println("\n----[ top ]----");
    System.err.println("123456789012345678901234567890");
    for (String s : textPair.getLeft()) {
        System.err.println(s);
    }
    System.err.println("\n----[ bottom ]----");
    System.err.println("123456789012345678901234567890");
    for (String s : textPair.getRight()) {
        System.err.println(s);
    }
}

From source file:com.quancheng.plugin.common.AbstractPrint.java

public void print() {
    String fileName = fileRootPath + "/" + StringUtils.replace(sourcePackageName.toLowerCase(), ".", "/") + "/"
            + className + ".java";
    File javaFile = new File(fileName);
    List<String> fileData = collectFileData();
    if (fileData != null) {
        try {/*from w  ww .  jav a  2  s. co m*/
            FileUtils.writeLines(javaFile, "UTF-8", fileData);
        } catch (IOException e) {
            throw new IllegalArgumentException("can not write file to" + fileName, e);
        }
    }
}

From source file:ch.cyberduck.core.nio.LocalHomeFinderFeature.java

protected Path toPath(final String home) {
    return new Path(StringUtils.replace(home, "\\", "/"), EnumSet.of(Path.Type.directory));
}

From source file:info.devbug.core.UnixCifsUrlConverter.java

private String convertWithSpaces(String cifsUrl) {
    return StringUtils.replace(cifsUrl, " ", "\\ ");
}

From source file:com.github.dozermapper.core.classmap.CopyByReference.java

private Pattern compilePattern(String mask) {
    String regexp = StringUtils.replace(mask, ".", "\\.");
    regexp = StringUtils.replace(regexp, WILDCARD, ".*?");
    return Pattern.compile(regexp);
}

From source file:com.casker.portfolio.domain.Portfolio.java

public void setDescription(String description) {
    this.description = StringUtils.replace(description, "\r\n", "<br/>");
}

From source file:eu.openanalytics.rpooli.web.BaseUriInjectionFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletRequest req = (HttpServletRequest) request;
    final String baseUri = StringUtils.replace(req.getRequestURL().toString(), req.getRequestURI(),
            req.getContextPath());//from  ww  w.  j a  v a 2  s . co m
    request.setAttribute("baseUri", baseUri);

    chain.doFilter(request, response);
}

From source file:io.wcm.devops.conga.generator.plugins.fileheader.JsonFileHeader.java

@Override
protected String sanitizeComment(String line) {
    return StringUtils.replace(StringUtils.replace(line, "/*", "/+"), "*/", "+/");
}

From source file:de.micromata.genome.util.matcher.LogicalMatcherFactory.java

/**
 * Prepare rule./*from   w  ww  .j av  a  2 s.  co  m*/
 *
 * @param rule the rule
 * @return the string
 */
private String prepareRule(String rule) {
    rule = StringUtils.replace(rule, " and ", " && ");
    rule = StringUtils.replace(rule, " or ", " || ");
    rule = StringUtils.replace(rule, " not ", " !");
    return rule;
}