Example usage for java.lang String startsWith

List of usage examples for java.lang String startsWith

Introduction

In this page you can find the example usage for java.lang String startsWith.

Prototype

public boolean startsWith(String prefix) 

Source Link

Document

Tests if this string starts with the specified prefix.

Usage

From source file:Main.java

public static String trimQuote(String origin) {
    String afterConvert = origin;
    if (origin.startsWith("\"") && origin.endsWith("\"")) {
        afterConvert = afterConvert.substring(1, afterConvert.length() - 1);
    }/*from   www  .j a va 2 s  . co  m*/
    return afterConvert;
}

From source file:Main.java

/**
 * A convenience method that allows for XML fragments, previously quoted
 * with the {@link #quoteXML(String)} method to be  unqoted again.
 * @param xmlFragment The fragment of XML to be unquoted.
 * @return A fragment of XML, no longer quoted.
 *//*from  w  ww . jav a  2  s  .  co m*/

public static String unquoteXML(String xmlFragment) {
    if (xmlFragment.startsWith(XML_QUOTE_PREFIX)) {
        return (xmlFragment.substring(XML_QUOTE_PREFIX.length(),
                xmlFragment.length() - XML_QUOTE_SUFFIX.length()));
    }
    return xmlFragment;
}

From source file:Main.java

/**
 * @throws IllegalArgumentException if {@code typeUrl} is in invalid format.
 *//*  ww w. j av a2  s.  c  om*/
public static void validate(String typeUrl) throws IllegalArgumentException {
    if (!typeUrl.startsWith(TYPE_URL_PREFIX)) {
        throw new IllegalArgumentException(String
                .format("Error: type URL %s is invalid; it must start with %s\n", typeUrl, TYPE_URL_PREFIX));
    }
}

From source file:Main.java

public static String getUrlFromUglyGoogleRedirect(String url) {
    if (url.startsWith("http://www.google.com/url?")) {
        url = url.substring("http://www.google.com/url?".length());
        String arr[] = urlDecode(url).split("\\&");
        if (arr != null)
            for (String str : arr) {
                if (str.startsWith("q="))
                    return str.substring("q=".length());
            }/*w w  w  .  j  a v  a  2 s  .c  om*/
    }

    return null;
}

From source file:Main.java

/**
 * A convenience method that allows for XML fragments to be stored in
 * larger XML documents without these fragments interfering with the 
 * containing document./*  w  w  w.  ja  v  a  2 s .  co m*/
 * @param xmlFragment The fragment of XML to be quoted.
 * @return A fragment of XML, quoted so it can be included within other
 *         XML documents without interference.
 */

public static String quoteXML(String xmlFragment) {
    if (!xmlFragment.startsWith(XML_QUOTE_PREFIX)) {
        return (XML_QUOTE_PREFIX + xmlFragment + XML_QUOTE_SUFFIX);
    }
    return xmlFragment;
}

From source file:Main.java

public static String getComponent(ResolveInfo info) {
    String packageName = info.activityInfo.packageName;
    String activityName = info.activityInfo.name;

    if (activityName.startsWith(packageName)) {
        return String.format("%s/%s", packageName, activityName.substring(packageName.length()));
    }//from w w  w  . j  a v  a2 s . c  o m

    return String.format("%s/%s", packageName, activityName);
}

From source file:Main.java

public static String getIPv4StringByStrippingIPv6Prefix(String in) {
    String ipv6Prefix = "::ffff:";

    if (in.startsWith(ipv6Prefix)) {
        return in.substring(ipv6Prefix.length(), in.length());
    }/*from   w w w .j a  v a  2  s  .c o  m*/

    return in;
}

From source file:Main.java

private static void setAlarm(Calendar calendar, String sTime) {

    String speech[] = sTime.split(" ");
    String time = speech[0];//w ww.j av a2s  .  c om
    String timeParts[] = time.split(":");
    int hour = Integer.parseInt(timeParts[0]);
    int minute = Integer.parseInt(timeParts[1]);
    String ampm = speech[1].toUpperCase();
    if (ampm.startsWith("P")) {
        hour += 12;
    }
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
}

From source file:Main.java

public static boolean contain(List<String> list, String cls) {
    for (String str : list) {
        if (cls.startsWith(str)) {
            return true;
        }/*from   w w  w  .j a v  a 2  s.c  o m*/
    }
    return false;
}

From source file:Main.java

private static Date parseDate(String d) throws IllegalArgumentException {
    if (!d.startsWith("@"))
        throw new IllegalArgumentException();
    return new Date(Long.parseLong(d.substring(1)));
}