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:com.github.bjoern2.codegen.util.LicenseUtils.java

public static String mit(int year, String owner) {
    String template = loadTemplate("mit.txt");
    template = template.replace("<year>", "" + year);
    template = template.replace("<copyright holders>", owner);
    return template;
}

From source file:org.jfrog.teamcity.agent.util.PathMatcher.java

private static String cleanPath(String relativePath) {
    relativePath = relativePath.replace('\\', '/');
    if (relativePath.startsWith("/") && relativePath.length() > 1) {
        return relativePath.substring(1);
    }/*from  w ww .  j  a va  2 s. co m*/
    return relativePath;
}

From source file:Main.java

public static String replaceHtmlStr(String strData) {
    if (strData == null) {
        return "";
    }/* w w  w  .  j av  a 2 s . c o  m*/
    strData = strData.replace("<", "&lt;");
    strData = strData.replace(">", "&gt;");
    strData = strData.replace("\"", "&quot;");
    return strData;
}

From source file:Main.java

public static double parseDS(String s) {
    return s != null && s.length() != 0 ? Double.parseDouble(s.replace(',', '.')) : 0;
}

From source file:Main.java

public static int getColorFromHex(String color) {
    if (color.contains("0x"))
        color = color.replace("0x", "");
    // if (color.contains("#"))
    // color = color.replace("#", "");
    // return Integer.parseInt(color, 16) + 0xFF000000;
    if (!color.contains("#")) {
        StringBuffer colorBuffer = new StringBuffer("#");
        colorBuffer.append(color);/*from  w  w w .ja  v  a  2s.c  om*/
        return Color.parseColor(colorBuffer.toString());
    }
    //
    return Color.parseColor(color);
    // StringBuffer colorBuffer = new StringBuffer("0xff");
    // colorBuffer.append(color);
    // int value = Integer.parseInt(colorBuffer.toString(), 16);
    // int red = ((value >> 24) & 0xFF) / 255;
    // int green = ((value >> 16) & 0xFF) / 255;
    // int blue = ((value >> 8) & 0xFF) / 255;
    // int alpha = ((value >> 0) & 0xFF) / 255;
    // Color.parseColor(colorString);
    // return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

/**
 * Formats the text while the user types for Expiration Date
 * @param et The edit text being worked on
 * @param textWatcher Text watcher to both remove and add back on. (Pass 'this' from class)
 * @param <T> T extends EditText/*from   w  ww . j a v a  2s  . c  om*/
 */
public static <T extends EditText> void formatExpirationDateWhileTyping(T et, TextWatcher textWatcher) {
    if (et == null) {
        return;
    }
    if (textWatcher == null) {
        return;
    }
    Editable s = et.getText();
    if (s == null) {
        return;
    }

    if (s.length() > 0) {
        String input = s.toString();
        input = input.replace("/", "");
        input = input.replace(" / ", "");
        if (input.length() <= 2) {
        } else if (input.length() >= 3 && input.length() <= 7) {
            String sub1 = input.substring(0, 2);
            String sub2 = input.substring(2);
            String toSet = sub1 + "/" + sub2;

            et.removeTextChangedListener(textWatcher);
            et.setText(toSet);
            et.setSelection(toSet.length());
            et.addTextChangedListener(textWatcher);
        }
    }
}

From source file:Main.java

/**
 * Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/'). Neither a leading nor trailing slash is added. The result could be concatenated with a slash and the name of a resource, and fed directly to <code>ClassLoader.getResource()</code>. For it to be fed to <code>Class.getResource</code> instead, a leading slash would also have to be prepended to the returned value.
 * //from   ww w.  ja va  2 s .c o  m
 * @param clazz
 *          the input class. A <code>null</code> value or the default (empty) package will result in an empty string ("") being returned.
 * @return a path which represents the package name
 * @see ClassLoader#getResource
 * @see Class#getResource
 */
public static String classPackageAsResourcePath(Class<?> clazz) {
    if (clazz == null) {
        return "";
    }
    String className = clazz.getName();
    int packageEndIndex = className.lastIndexOf('.');
    if (packageEndIndex == -1) {
        return "";
    }
    String packageName = className.substring(0, packageEndIndex);
    return packageName.replace('.', '/');
}

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

public static String gpl30(String libraryName, int year, String owner) {
    String template = loadTemplate("gpl30.txt");
    template = template.replace("<year>", "" + year);
    template = template.replace("<name of author>", owner);
    template = template.replace("<one line to give the program's name and a brief idea of what it does.>",
            libraryName);/* www. ja v a 2  s  . c  o  m*/
    return template;
}

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

public static String lgpl21(String libraryName, int year, String owner) {
    String template = loadTemplate("lgpl21.txt");
    template = template.replace("<year>", "" + year);
    template = template.replace("<name of author>", owner);
    template = template.replace("<one line to give the library's name and an idea of what it does.>",
            libraryName);/*from   ww  w.j  a v  a2s  .c o m*/
    return template;
}

From source file:Main.java

private static String sqlUnEscapeString(String aString) {

    String aReturn = "";

    if (null != aString) {
        aReturn = aString.replace("''", "'");
    }/*from  ww  w.  ja  va  2 s .c o m*/

    return aReturn;
}