Java String Split splitStringWithoutTrim(String strInput, String strSplitor)

Here you can find the source of splitStringWithoutTrim(String strInput, String strSplitor)

Description

Split String to List

License

Open Source License

Parameter

Parameter Description
strInput String with splitor
strSplitor Splitor, such as ',' '|'

Return

String Item in List

Declaration

public static List splitStringWithoutTrim(String strInput, String strSplitor) 

Method Source Code

//package com.java2s;
/*//from   w ww . j  a v a  2 s  .  c o  m
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.util.List;
import java.util.ArrayList;

public class Main {
    /**
     * Split String to List
     *
     * @param strInput   String with splitor
     * @param strSplitor Splitor, such as ',' '|'
     * @return String Item in List
     */
    public static List splitStringWithoutTrim(String strInput, String strSplitor) {
        List listResult = new ArrayList();
        if (strInput == null) {
            return null;
        }
        int start = 0;
        int end = strInput.length();

        while (start < end) {
            int delimIdx = strInput.indexOf(strSplitor, start);

            if (delimIdx < 0) {
                String tok = strInput.substring(start);
                listResult.add(tok);
                start = end;
            } else {
                String tok = strInput.substring(start, delimIdx);
                listResult.add(tok);
                start = delimIdx + strSplitor.length();
            }
        }

        return listResult;
    }

    /**
     * Find substring start by one string end by another string
     *
     * @param src   source string to be split
     * @param start start string
     * @param end   end string
     * @return string between start and end
     */
    public static String subString(String src, String start, String end) {
        int iStart = src.indexOf(start);
        int iEnd = src.indexOf(end);
        if ((iStart == -1) || (iEnd == -1)) {
            return null;
        }
        iEnd += end.length();
        return src.substring(iStart, iEnd + 1);
    }

    /**
     * Find substring start by one string end by index
     *
     * @param src   source string to be split
     * @param start start string
     * @param end   end index
     * @return string between start and end
     */
    public static String subString(String src, String start, int end) {
        int iStart = src.indexOf(start);
        if ((iStart == -1) || (end == -1)) {
            return null;
        }
        return src.substring(iStart, end);
    }

    /**
     * Find substring start by one index end by index
     *
     * @param src        string to be splited
     * @param startIndex start index
     * @param endIndex   end index
     * @return string between start and end
     */
    public static String subString(String src, int startIndex, int endIndex) {
        if ((startIndex == -1) || (endIndex == -1)) {
            return null;
        }
        return src.substring(startIndex, endIndex);
    }

    /**
     * Find substring start by first index and end by length
     *
     * @param src    source string to be split
     * @param length end index
     * @return string between start and end
     */
    public static String subString(String src, int length) {
        if (src == null) {
            return "";
        }
        if (src.length() <= length) {
            return src;
        } else {
            return src.substring(0, length);
        }
    }
}

Related

  1. splitString(String string)
  2. splitString(String string, int limit)
  3. splitStringBySeperator(final String str, final String seperator)
  4. splitStrings(String start, String end, int numSplitStrings, boolean oddLevel, List splits)
  5. splitStringToList(String pstrString, String pstrSep)
  6. splitStruct(String struct)
  7. splitSubstring(String str, String substr)
  8. splitTags(final String tagsString)
  9. splitTags(String rawTags)