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

public static int[] fromIntString(String string) {
    String[] strings = string.replace("[", "").replace("]", "").split(", ");
    int result[] = new int[strings.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = Integer.parseInt(strings[i]);
    }//w ww .  jav  a2 s  .co  m
    return result;
}

From source file:Main.java

/**
 * use to show address location pin on map.
 *
 * @param mContext/*w  ww. ja  v a  2 s .  c  o  m*/
 * @param address  to show on map.
 */
public static void showAddressOnMap(Context mContext, String address) {
    address = address.replace(' ', '+');
    Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));
    mContext.startActivity(geoIntent);
}

From source file:Main.java

public static float[] fromFloatString(String string) {
    String[] strings = string.replace("[", "").replace("]", "").split(", ");
    float result[] = new float[strings.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = Float.parseFloat(strings[i]);
    }/*from w  w  w  .ja va  2 s. com*/
    return result;
}

From source file:Main.java

/** Method to escape &lt; and &gt; chars.
 * @param input The input string/* ww w .ja va2  s  . com*/
 * @return The escaped string
 */
public static String escapeTags(String input) {
    return input.replace("<", "&lt;").replace(">", "&gt;");
}

From source file:Main.java

/**
 * Convert a "/"-based resource path to a "."-based fully qualified class name.
 * // www .j a  v  a 2 s  .  com
 * @param resourcePath
 *          the resource path pointing to a class
 * @return the corresponding fully qualified class name
 */
public static String convertResourcePathToClassName(String resourcePath) {
    return resourcePath.replace('/', '.');
}

From source file:Main.java

private static String removeLineBreaks(String message) {
    return message.replace("\n", "").replace("\r", "");
}

From source file:Main.java

/**
 * This method will extract a resType from an URI. 
 * //  w  w w . ja  v a2  s. c om
            
 * @param idUri The URI containing the Id
 * @return A resType (extracted from the URI or left unchanged)
 */
public static String extractResTypeFromURI(String idUri) {
    String s = idUri.replace("http://musicbrainz.org/", "");

    String[] f = s.split("/");
    if (f == null || f.length < 2)
        return idUri;
    else
        return f[0];
}

From source file:Main.java

public static String TransformString(String chgtext) {
    String convTxt = chgtext;
    convTxt = convTxt.replace("&quot;", "'");
    convTxt = convTxt.replace("&quot;", "'");
    convTxt = convTxt.replace("&ldquo;", "'");
    convTxt = convTxt.replace("&rdquo;", "'");
    convTxt = convTxt.replace("&nbsp;", " ");
    return convTxt;
}

From source file:Main.java

public static String replaceHtmlChar(String str) {
    String htmlstring = str;
    htmlstring = htmlstring.replace("&amp;", "&");
    htmlstring = htmlstring.replace("&nbsp;", " ");
    htmlstring = htmlstring.replace("&lt;", "<");
    htmlstring = htmlstring.replace("&gt;", ">");
    return htmlstring;
}

From source file:Main.java

public static int getHexColorFromString(String str_value) {
    str_value = str_value.replace("#", "");
    if (str_value.length() == 6) { //RRGGBB
        return new BigInteger("ff" + str_value, 16).intValue();
    } else if (str_value.length() == 8) { //AARRGGBB
        return new BigInteger(str_value, 16).intValue();
    } else {/*  www.  j a  va2  s  . co  m*/
        return 0xffffffff;
    }
}