Example usage for org.apache.commons.lang StringUtils substring

List of usage examples for org.apache.commons.lang StringUtils substring

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substring.

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:MainClass.java

public static void main(String[] args) {

    //SubString/* w ww .  j  a  va 2 s  . c  o m*/
    System.out.println("8) Substring >>>" + StringUtils.substring("SUBSTRING", 1, 5));
}

From source file:StringUtilsTrial.java

public static void main(String[] args) {

    // SubString/* w ww  .  ja  va 2  s  . c  om*/
    System.out.println("8) Substring >>>" + StringUtils.substring("SUBSTRING", 1, 5));

}

From source file:com.dianping.lion.util.ThrowableUtils.java

public static String extractStackTrace(Throwable t, int maxLen) {
    StringWriter me = new StringWriter();
    PrintWriter pw = new PrintWriter(me);
    t.printStackTrace(pw);/* www  . ja v  a2s. c om*/
    pw.flush();
    return StringUtils.substring(me.toString(), 0, maxLen);
}

From source file:com.khs.report.Data.java

public static Data convertToData(String id, String s, Integer length) {
    if (length != null) {
        s = StringUtils.substring(s, 0, length);
    }// www  .  j  a v  a2 s .com
    return new Data(id, s);
}

From source file:com.google.ie.common.util.StringUtility.java

/**
 * This method breaks a single String into a list of Strings. The string is
 * split after every 500 characters./* w  w w .  j a v  a2  s  . c om*/
 * 
 * @param string The string to be split
 */
public static final List<String> convertStringToList(String string) {
    int length = StringUtils.length(string);
    /* Calculate the number of times the string is to be split */
    int numOfSplits = length / DATASTORE_ALLOWED_LENGTH_FOR_STRING;
    if (length % DATASTORE_ALLOWED_LENGTH_FOR_STRING > 0) {
        numOfSplits += 1;
    }
    List<String> strings = null;
    if (numOfSplits > 0) {
        strings = new ArrayList<String>();
        int offset = 0;
        for (int i = 0; i < numOfSplits; i++) {
            strings.add(StringUtils.substring(string, offset, offset + DATASTORE_ALLOWED_LENGTH_FOR_STRING));
            offset += DATASTORE_ALLOWED_LENGTH_FOR_STRING;
        }
    }
    return strings;
}

From source file:com.hangum.tadpole.rdb.core.editors.main.utils.SQLTextUtil.java

/**
 * cursor object arry//w ww. j av a  2s.c o m
 * 
 * @param strQuery
 * @param intPosition
 * @param startIndex
 * @param endIndex
 * @return
 */
private static String[] cusrsotObjectArry(String strQuery, int intPosition, int startIndex, int endIndex) {
    String[] arryCursor = { "", "" };

    String strPosTxt = StringUtils.trimToEmpty(StringUtils.substring(strQuery, startIndex, endIndex));
    //      if(logger.isDebugEnabled()) logger.debug("==> postion char : " + strPosTxt);
    if (StringUtils.isEmpty(strPosTxt))
        return arryCursor;

    String strBeforeTxt = strQuery.substring(0, startIndex);
    String[] strArryBeforeTxt = StringUtils.split(strBeforeTxt, ' ');

    //    ? ?  .
    String strAfterTxt = strQuery.substring(startIndex);
    String[] strArryAfterTxt = StringUtils.split(strAfterTxt, ' ');

    if (strArryBeforeTxt.length == 0) {
        arryCursor[0] = removeSpecialChar(strArryAfterTxt[0]);
        arryCursor[1] = "";
    } else {
        arryCursor[0] = removeSpecialChar(strArryBeforeTxt[strArryBeforeTxt.length - 1]);
        arryCursor[1] = removeSpecialChar(strArryAfterTxt[0]);
    }
    return arryCursor;
}

From source file:edu.mayo.cts2.framework.plugin.service.lexevs.uri.UriUtils.java

/**
 * Gets the namespace part of a URI.//  w  w w .j a v a 2  s.  com
 *
 * @param uri the uri
 * @return the namespace
 */
public static String getNamespace(String uri) {
    int separator = getSeparatorPosition(uri);

    return StringUtils.substring(uri, 0, separator);
}

From source file:edu.sampleu.demo.kitchensink.UITestPropertyEditor.java

/**
 * @see java.beans.PropertyEditorSupport#getAsText()
 *///from w w  w .j  a v a  2  s . co m
@Override
public String getAsText() {
    Object obj = this.getValue();

    if (obj == null) {
        return null;
    }

    String displayValue = obj.toString();
    if (displayValue.length() > 3) {
        displayValue = StringUtils.substring(displayValue, 0, 3) + "-" + StringUtils.substring(displayValue, 3);
    }

    return displayValue;
}

From source file:com.inktomi.wxmetar.MetarParser.java

/**
 * Parses a String[] of metar parts into a Metar
 * <p/>//www  . j a v a  2s .  co m
 * KCLE 050551Z 17012G24KT 10SM SCT070 SCT085 OVC110 09/03 A3005 RMK AO2 SLP180 8/57/ 60004 T00940028 10094 20061 56026
 * KL35 051752Z AUTO 26006KT 10SM CLR 11/M19 A3030 RMK AO2
 *
 * @param tokens the tokens to parse
 * @return the assembled Metar
 */
private static Metar parseTokens(final String[] tokens) {
    Metar rval = new Metar();

    rval.station = tokens[0];

    // The day of the month is the first 2
    rval.dayOfMonth = Integer.parseInt(StringUtils.substring(tokens[1], 0, 2));

    // The time is from 0 to length-1
    rval.zuluHour = Integer.parseInt(StringUtils.substring(tokens[1], 2, tokens[1].length() - 3));
    rval.zuluMinute = Integer.parseInt(StringUtils.substring(tokens[1], 4, tokens[1].length() - 1));

    // We start our actual parsing at the third element
    for (int i = 2; i < tokens.length; i++) {
        String token = tokens[i];
        String nextToken = null;
        if (tokens.length > i + 1) {
            nextToken = tokens[i + 1];
        }

        // First, we have AUTO or COR
        if (parseModifier(token, rval)) {
            continue;
        }

        if (parseWinds(token, rval)) {
            continue;
        }

        if (null != nextToken && parseVisibility(token, nextToken, rval)) {
            Matcher numberMatcher = NUMBER.matcher(token);
            Matcher fractionMatcher = FRACTION.matcher(nextToken);

            if (!StringUtils.endsWith(token, "SM") && numberMatcher.matches()
                    && StringUtils.endsWith(nextToken, "SM") && fractionMatcher.matches()) {

                // Increment i one here since we had a fraction: 1 1/2SM
                i = i + 1;
            }

            continue;
        }

        if (parsePresentWeather(token, rval)) {
            continue;
        }

        if (parseClouds(token, rval)) {
            continue;
        }

        if (parseTempDewpoint(token, rval)) {
            continue;
        }

        if (parseAltimeter(token, rval)) {
            continue;
        }

    }

    return rval;
}

From source file:com.prowidesoftware.swift.model.mt.AckSystemMessage.java

public String getErrorCode() {
    final Tag t = super.m.getBlock4().getTagByName("405");
    if (t == null)
        return null;
    return StringUtils.substring(t.getValue(), 0, 3);
}