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 List<String> getDexEntries() {
    try {//  ww w.ja  v a 2s .  com
        Object app = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
        Object codePath = Class.forName("android.app.Application").getMethod("getPackageCodePath").invoke(app);
        Class<?> dexFileClass = Class.forName("dalvik.system.DexFile");
        Object dexFile = dexFileClass.getConstructor(String.class).newInstance(codePath);
        Enumeration<String> entries = (Enumeration<String>) dexFileClass.getMethod("entries").invoke(dexFile);
        List<String> dexEntries = new LinkedList<String>();
        while (entries.hasMoreElements()) {
            String entry = entries.nextElement();
            entry = entry.replace('.', '/') + ".class";
            dexEntries.add(entry);
        }
        dexFileClass.getMethod("close").invoke(dexFile);
        return dexEntries;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String removeBlankSpace(String value) {
    value = value.replace(" ", "");
    return value;
}

From source file:Main.java

public static String getBaseType(String typeName) {
    String ret = typeName.substring(typeName.lastIndexOf('.') + 1);
    return ret.replace("[]", "");
}

From source file:Main.java

/**
 * Convert string format date data to whooing date format integer
 * @param   dateStr     Date data formatted string like "05/21"
 * @return   Return whooing style integer date like 20121212 otherwise -1
 * *//*  w  ww . j a  va 2  s .  c  o m*/
static public int convertWhooingDate(String dateStr) {
    String convertDate = dateStr.replace("/", "");
    if (convertDate.length() == 3) {
        convertDate = "0" + convertDate;
    }
    Calendar rightNow = Calendar.getInstance();

    int year = rightNow.get(Calendar.YEAR);
    int month = rightNow.get(Calendar.MONTH) + 1;
    int day = rightNow.get(Calendar.DAY_OF_MONTH);

    int today = year * 10000 + month * 100 + day;
    convertDate = year + convertDate;
    int convertDateInt = 0;
    try {
        convertDateInt = Integer.valueOf(convertDate);
        // In case of receiving message 12/31 on 1 Jan
        if ((today / 10000) < (convertDateInt / 10000)) {
            convertDateInt -= 10000;
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    //guard wrong date
    if (convertDateInt < ((year * 10000) + 101)) {
        convertDateInt = today;
    }
    return convertDateInt;
}

From source file:DateUtils.java

/**
    * A method used to build a date for use Marker XML and KML data
    */*  w  ww. j  a  v a2 s  .c  o m*/
    * @param year  the year component of the date
    * @param month the month component of the date
    * @param day   the day component of the month
    *
    * @return      a string containing the finalised date
    */
public static String buildDate(String year, String month, String day) {

    // check for at least a year
    if (year != null) {

        String date = year + "-" + month + "-" + day;
        date = date.replace("-null", "");
        date = date.replace("null", "");

        return date;
    } else {
        return "";
    }

}

From source file:com.enonic.cms.business.localization.resource.LocalizationResourceBundleUtils.java

public static Locale parseLocaleString(String localeAsString) {
    localeAsString = localeAsString.replace('-', '_');

    Matcher matcher = RegexpUtil.match(localeAsString, LOCALE_PATTERN, Pattern.CASE_INSENSITIVE);

    String language = "";
    String country = "";
    String variant = "";

    if (matcher.matches()) {
        language = getLanguageFromMatcher(matcher);
        country = getCountryFromMatcher(matcher);
        variant = getVariantFromMatcher(matcher);
    } else {//from  ww  w.  j a  v a 2s.com
        throw new LocaleParsingException(
                "Could not parse locale string: " + localeAsString + " to valid locale");
    }

    return new Locale(language, country == null ? "" : country, variant == null ? "" : variant);
}

From source file:de.peterspan.csv2db.converter.AbstractDataLine.java

public static Double string2double(String value) {
    try {// w ww .ja v a  2  s. c om
        value = value.replace(",", ".");
        return Double.parseDouble(value);
    } catch (NumberFormatException nfe) {
        if (!value.isEmpty()) {
            log.error("Could not convert string " + value + " to double.", nfe);
        }
        return null;
    }
}

From source file:Main.java

public static String filterBlankSpace(String str) {
    if (str == null || "null".equalsIgnoreCase(str)) {
        return "";
    }// w  w w . jav  a  2 s .c  o m
    return str.replace(" ", "");
}

From source file:Main.java

public static String chkHttpsAtPrefixs(String _url) {
    if (isFindHttpAtPrefixs(_url)) {
        return _url.replace("(?i)" + "http://", "");
    } else if (isFindHttpsAtPrefixs(_url)) {
        return _url.replace("(?i)" + "https://", "");
    }//from   ww w .  ja  v a 2 s  . c o m
    return (isFindHttpAtPrefixs(_url)) ? _url.replace("http://", "") : _url;

}

From source file:Main.java

public static boolean isIP(String input) {

    if (input.contains(".") && input.length() > 1) {
        return TextUtils.isDigitsOnly(input.replace(".", "").trim());
    } else {// ww  w.  j  a  va 2  s  .  co m
        return false;
    }
}