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:co.edu.unal.arqdsoft.presentacion.JSON.java

/**
 *
 * @param is/*from  ww w  .jav  a  2 s .co  m*/
 * @return
 */
public static String getTemplate(InputStream is) {
    try {
        byte[] charr = new byte[is.available()];
        is.read(charr);
        String text = new String(charr, "UTF-8");
        text = text.replace("\n", "").replace("\r", "").replace("  ", "").replace("\"", "'");
        return text;
    } catch (IOException ex) {
        Logger.getLogger(JSON.class.getName()).log(Level.SEVERE, null, ex);
        return "";
    }
}

From source file:Main.java

public static int getMatchingThresholdFromString(String value) throws ParseException {
    char percent = new DecimalFormatSymbols().getPercent();
    value = value.replace(percent, ' ');
    Number number = NumberFormat.getNumberInstance().parse(value);
    double parse = number.doubleValue();
    double p = Math.log10(Math.max(Double.MIN_VALUE, Math.min(1, parse / 100)));
    return Math.max(0, (int) Math.round(-12 * p));
}

From source file:Main.java

public static boolean isMobile(String phoneNum) {
    if (phoneNum == null)
        return false;
    return validation("^[1][3,4,5,7,8][0-9]{9}$", phoneNum.replace("+86", ""));
}

From source file:disko.utils.DiscoProxySettings.java

/**
 * //w  w w. j a va  2 s. c o m
 * <p>
 * Convenience method to open a URL connection by using the
 * proxy settings. If proxyHost is null, the default is to  just
 * call <code>url.openConnection</code>.
 * </p>
 *
 * @param url
 * @return
 */
public static URLConnection newConnection(URL url) throws IOException {
    URLConnection connection;
    String externalForm = url.toExternalForm();
    url = new URL(externalForm.replace(" ", "%20"));
    if (DiscoProxySettings.proxyHost != null) {
        connection = url.openConnection(new Proxy(Proxy.Type.HTTP,
                new InetSocketAddress(DiscoProxySettings.proxyHost, DiscoProxySettings.proxyPort)));
        if (DiscoProxySettings.proxyUser != null) {
            String enc = new String(Base64.encodeBase64(
                    new String(DiscoProxySettings.proxyUser + ":" + DiscoProxySettings.proxyPassword)
                            .getBytes()));
            connection.setRequestProperty("Proxy-Authorization", "Basic " + enc);
        }
    } else
        connection = url.openConnection();
    return connection;
}

From source file:Main.java

/**
 * Get a list of all saved characters names.
 *///from w  w  w.  j  a v a2  s . com
public static List<String> listCharacterNames(Context context) {
    List<String> names = new ArrayList<>();

    for (String name : context.fileList()) {
        if (name.startsWith(CORE_PREFIX)) {
            names.add(name.replace(CORE_PREFIX, ""));
        } else if (name.startsWith(FAE_PREFIX)) {
            names.add(name.replace(FAE_PREFIX, ""));
        }
    }

    return names;
}

From source file:Main.java

public static String HttpGet(String url) {
    HttpClient client = new DefaultHttpClient();
    StringBuilder builder = new StringBuilder();
    HttpGet myget = new HttpGet(url);
    try {/*from   w  w w .  j av  a2  s. co  m*/
        HttpResponse response = client.execute(myget);
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        for (String s = reader.readLine(); s != null; s = reader.readLine()) {
            builder.append(s);
        }

        char cr = 65279;
        String t = String.valueOf(cr);
        String resultString = builder.toString();
        resultString = resultString.replace("\t", "").replace(t, "");

        return resultString;

    } catch (Exception e) {
        Log.v("url response", "false");
        e.printStackTrace();
    }
    return null;
}

From source file:vn.chodientu.component.imboclient.util.TextUtils.java

/**
 * Normalize color definition/*from w  ww.ja  v  a 2 s  .  c o  m*/
 *
 * @param color Input color definition
 * @return Normalized color definition
 */
public static String normalizeColor(String color) {
    return color.replace("#", "").toLowerCase();
}

From source file:com.francetelecom.clara.cloud.techmodel.cf.EnvVariableKey.java

/**
 * Returning a changed key to be compatible with Linux env variable constraints.
 * - replace . with a _ (dot / underscore)
 * - TBC/*from  w ww.  j ava 2s  .c o m*/
 * @return
 */
public static String escapeToSystemEnvVariableName(String intialKey) {
    String escapedKey = intialKey.replace('.', '_');
    if (!escapedKey.equals(intialKey)) {
        logger.debug("replace initial key {} with escaped key {}", intialKey, escapedKey);
    }
    return escapedKey;
}

From source file:com.github.alexfalappa.nbspringboot.Utils.java

/**
 * Simplistic escape of angled brackets in the given string.
 *
 * @param text the string to escape//ww  w.j a v a2s.  c om
 * @return escaped string
 */
public static String simpleHtmlEscape(String text) {
    return text.replace("<", "&lt;").replace(">", "&gt;");
}

From source file:com.vmware.o11n.plugin.powershell.remote.impl.BasePowerShellTerminal.java

private static String replacePlaceholderVariablesWithConstants(String templateScript) {
    templateScript = templateScript.replace("{#SCRIPT_SERIALIZER_METHOD_NAME#}", SCRIPT_SERIALIZER_METHOD_NAME);
    templateScript = templateScript.replace("{#SCRIPT_SERIALIZER_METHOD_NAME#}", SCRIPT_SERIALIZER_METHOD_NAME);
    templateScript = templateScript.replace("{#ERRORS_START#}", ERRORS_START);
    templateScript = templateScript.replace("{#ERRORS_END#}", ERRORS_END);
    templateScript = templateScript.replace("{#OUTPUT_START#}", OUTPUT_START);
    templateScript = templateScript.replace("{#OUTPUT_END#}", OUTPUT_END);
    templateScript = templateScript.replace("{#RESULT_DELIMITER#}", RESULT_DELIMITER_END);
    return templateScript;
}