Example usage for java.lang String replaceFirst

List of usage examples for java.lang String replaceFirst

Introduction

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

Prototype

public String replaceFirst(String regex, String replacement) 

Source Link

Document

Replaces the first substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:com.jk.util.JKStringUtil.java

/**
 * Compile.//from  ww w  .  j av  a  2s  . c  o  m
 *
 * @param sql
 *            the sql
 * @param param
 *            the param
 * @return the string
 */
public static String compile(String sql, final Object... param) {
    for (final Object element : param) {
        sql = sql.replaceFirst("\\?", element.toString());
    }
    return sql;
}

From source file:Main.java

public static String replaceStr(Context context, int resId, String... replaces) {
    String result = context.getResources().getString(resId);
    if (isEmpty(result)) {
        return "";
    }//from  w  w  w. ja  v a  2 s  .c  om

    if (replaces == null || 0 == replaces.length) {
        return result;
    }

    for (int i = 0; i < replaces.length; i++) {
        result = result.replaceFirst("#a#", replaces[i]);
    }

    return result;
}

From source file:jodtemplate.template.expression.DefaultExpressionHandler.java

private static String replaceInlineListItemWithVariable(final String text, final String replace) {
    return text.replaceFirst("\\" + INLINE_LIST_ITEM_BEGIN + ".*?\\" + INLINE_LIST_ITEM_END, replace);
}

From source file:Main.java

public static String encodeUrl(String inputUrl) {

    if (isBlank(inputUrl))
        return inputUrl;

    char[] charArray = inputUrl.toCharArray();
    for (int i = 0; i < charArray.length; i++) {
        if ((charArray[i] >= 0x4e00) && (charArray[i] <= 0x9fbb)) {
            inputUrl = inputUrl.replaceFirst(String.valueOf(charArray[i]),
                    URLEncoder.encode(String.valueOf(charArray[i])));

        }/*from w  w  w  .  j  av  a2s .co  m*/
    }
    return inputUrl;
}

From source file:net.andydvorak.intellij.lessc.fs.VirtualFileLocationChange.java

@Nullable
private static String toCssPath(final String lessPath) {
    return lessPath == null ? null : lessPath.replaceFirst("\\.less$", ".css");
}

From source file:eu.hydrologis.jgrass.geonotes.util.ExifHandler.java

/**
 * Extract the creation {@link DateTime} from the map of tags read by {@link #readMetaData(File)}.
 * //from w w  w  .ja v a 2s. c o  m
 * @param tags2ValuesMap the map of tags read by {@link #readMetaData(File)}.
 * @return the datetime.
 */
public static DateTime getCreationDatetimeUtc(HashMap<String, String> tags2ValuesMap) {
    String creationDate = tags2ValuesMap.get(TiffConstants.EXIF_TAG_CREATE_DATE.name);
    creationDate = creationDate.replaceAll("'", "");
    creationDate = creationDate.replaceFirst(":", "-");
    creationDate = creationDate.replaceFirst(":", "-");

    String dateTimeFormatterYYYYMMDDHHMMSS_string = "yyyy-MM-dd HH:mm:ss";
    DateTimeFormatter dateTimeFormatterYYYYMMDDHHMMSS = DateTimeFormat
            .forPattern(dateTimeFormatterYYYYMMDDHHMMSS_string);

    DateTime parseDateTime = dateTimeFormatterYYYYMMDDHHMMSS.parseDateTime(creationDate);
    DateTime dt = parseDateTime.toDateTime(DateTimeZone.UTC);
    return dt;
}

From source file:com.diyshirt.util.RegexUtil.java

/**
 * obfuscate plaintext emails: makes them
 * "human-readable" - still too easy for
 * machines to parse however.// w  w w .j  a va  2s . c  o  m
 */
public static String obfuscateEmail(String str) {
    Matcher emailMatch = emailPattern.matcher(str);
    while (emailMatch.find()) {
        String at = emailMatch.group(1);
        //System.out.println("at=" + at);
        str = str.replaceFirst(at, "-AT-");

        String dot = emailMatch.group(2) + emailMatch.group(3) + emailMatch.group(4);
        String newDot = emailMatch.group(2) + "-DOT-" + emailMatch.group(4);
        //System.out.println("dot=" + dot);
        str = str.replaceFirst(dot, newDot);
    }
    return str;
}

From source file:api.wiki.WikiGenerator.java

private static String stripPackage(String name) {
    return name.replaceFirst("^.*\\.", "");
}

From source file:com.mseeworld.qzh.util.Debug.java

/**
 * ?/* w  ww.  ja v  a  2s  . co m*/
 * @param objects
 * @date    2013-5-8
 */
public static final void printf(String msg, Object... objects) {
    if (ArrayUtils.isEmpty(objects)) {
        System.out.println(msg);
        return;
    }
    for (int i = 0, len = objects.length; i < len; i++) {
        Object obj = objects[i];
        msg = msg.replaceFirst("\\{\\}", obj == null ? "" : obj.toString());
    }
    System.out.println(msg);
}

From source file:com.ts.db.connector.ConnectorDriverManager.java

private static Driver getDriver(File jar, String url, ClassLoader cl) throws IOException {
    ZipFile zipFile = new ZipFile(jar);
    try {/*from   w  w w. j  a v  a  2s. c  o  m*/
        for (ZipEntry entry : Iteration.asIterable(zipFile.entries())) {
            final String name = entry.getName();
            if (name.endsWith(".class")) {
                final String fqcn = name.replaceFirst("\\.class", "").replace('/', '.');
                try {
                    Class<?> c = DynamicLoader.loadClass(fqcn, cl);
                    if (Driver.class.isAssignableFrom(c)) {
                        Driver driver = (Driver) c.newInstance();
                        if (driver.acceptsURL(url)) {
                            return driver;
                        }
                    }
                } catch (Exception ex) {
                    if (log.isTraceEnabled()) {
                        log.trace(ex.toString());
                    }
                }
            }
        }
    } finally {
        zipFile.close();
    }
    return null;
}