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 Date parseRFC822Date(String date) {
    Date result = null;/*from   ww  w  .  j  av a 2  s .c o m*/
    if (date.contains("PDT")) {
        date = date.replace("PDT", "PST8PDT");
    }
    if (date.contains(",")) {
        // Remove day of the week
        date = date.substring(date.indexOf(",") + 1).trim();
    }
    SimpleDateFormat format = RFC822Formatter.get();
    for (int i = 0; i < RFC822DATES.length; i++) {
        try {
            format.applyPattern(RFC822DATES[i]);
            result = format.parse(date);
            break;
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    if (result == null) {
        Log.e(TAG, "Unable to parse feed date correctly");
    }

    return result;
}

From source file:jetbrick.tools.chm.reader.AnchorNameManager.java

public static void addAnchor(File file, String encoding) throws IOException {
    String html = FileUtils.readFileToString(file, encoding);
    html = html.replace('$', '\uFFE5');

    Pattern p = Config.style.getAnchorNameRegex();
    Matcher m = p.matcher(html);/*from  w ww  .  j av  a 2s.c  om*/

    int findCount = 0;
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        findCount++;
        String anchor = m.group(1);
        // String oldAnchor = m.group();
        String oldAnchor = "<A HH=\"1\" NAME=\"" + anchor + "\">";
        String newAnchor = "<A HH=\"1\" NAME=\"" + getNewAnchorName(anchor) + "\"></A>";
        m.appendReplacement(sb, newAnchor + oldAnchor);
    }
    m.appendTail(sb);

    System.out.println("addAnchor(" + findCount + ") : " + file);

    if (findCount > 0) {
        html = sb.toString().replace('\uFFE5', '$');
        FileUtils.writeStringToFile(file, html, encoding);
    }
    html = null;
}

From source file:com.epam.cme.storefront.util.MetaSanitizerUtil.java

/**
 * Removes all HTML tags and double quotes and returns a String
 * //  ww w .ja  v a 2  s  . c  o m
 * @param s
 *            Description to be sanitized
 * @return String object
 */
public static String sanitizeDescription(final String s) {
    if (s != null) {
        final String clean = Jsoup.parse(s).text();
        return clean.replace("\"", "");
    } else {
        return "";
    }
}

From source file:edu.pitt.dbmi.ipm.service.EnterpriseAnalytics.java

/**
 * /*www .  ja  va  2s.c o m*/
 * @param diseaseAbbr
 *            - example: "brca", "ov", "hnsc"
 * @param tssName
 *            - name of tissue source site for ex.
 *            "University of Pittsburgh"
 * @return number of patients for a particular disease and tss as JsonObject
 * @throws QueryException
 */
public static JSONObject countPatientsByTSS(String diseaseAbbr, String tssName) throws QueryException {
    initParams();

    String q = count_patients_by_tss_Q.replace("<diseaseAbbr>", diseaseAbbr.toLowerCase());
    q = q.replace("<tssName>", tssName);
    try {
        return StorageFactory.getStorage().getJSONResult(StorageFactory.getStorage().getSparqlURL(), q);
    } catch (QueryException e) {
        throw e;
    }

}

From source file:Main.java

/**
 * Renders an XML node to a string/*from w  w  w  .jav a 2s.  c o m*/
 * @param node The xml node to render
 * @param stripHeader If true, strips the auto-generated XML header from the generated string
 * @return the rendered string or null if it failed conversion
 */
public static String renderNode(final Node node, final boolean stripHeader) {
    if (node == null)
        return null;
    try {
        StringWriter writer = new StringWriter();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(new DOMSource(node), new StreamResult(writer));
        final String s = writer.toString();
        if (stripHeader) {
            return s.replace(XML_HEADER, "");
        }
        return s;
    } catch (Throwable e) {
        return null;
    }
}

From source file:de.snertlab.xdccBee.irc.DccMessageParser.java

private static String cleanMessage(String message) {
    String s = message;
    s = delete_control_codes(message);//from  w w w .  j  ava  2s  .c o  m
    s = s.replace("^\\s+|\\s+$", "");
    return s;
}

From source file:Main.java

public static void deleteDatabase(Context context, String name) {
    String dbName = formatDatabaseName(context, name);
    if (!context.deleteDatabase(dbName)) {
        context.deleteDatabase(dbName.replace(":", "_"));
    }//  w  ww .ja v  a 2  s  .co m
}

From source file:AIR.Common.Utilities.Path.java

public static String combine(String dir, String fileName, String separator) {
    // TODO: needs review
    dir = dir.replace("/", separator);
    dir = dir.replace("\\", separator);
    // End/*  w w w  . j  a v a 2s  .  c o m*/
    if (StringUtils.isEmpty(dir))
        return fileName;
    else if (StringUtils.isEmpty(fileName))
        return dir;
    if (dir.endsWith(separator) || fileName.startsWith(separator)) {
        return String.format("%s%s", dir, fileName);
    } else {
        return String.format("%s%s%s", dir, separator, fileName);
    }
}

From source file:Main.java

public static boolean isOnClasspath(String fullyQualifiedName, IJavaProject project) {
    if (fullyQualifiedName.indexOf('$') != -1)
        fullyQualifiedName = fullyQualifiedName.replace('$', '.');
    try {/*ww  w. j a  va  2 s . co  m*/
        IType type = project.findType(fullyQualifiedName);
        return type != null && type.exists();
    } catch (JavaModelException e) {
    }
    return false;
}

From source file:com.thoughtworks.go.util.TestUtils.java

public static Matcher<? super String> isSameAsPath(final String expected) {
    final String expectedPath = expected.replace('/', File.separatorChar);

    return new TypeSafeMatcher<String>() {
        @Override/*from ww  w.  j av  a 2  s .  c om*/
        protected boolean matchesSafely(String actual) {
            return expectedPath.equals(actual);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(expectedPath);
        }
    };
}