Java String Split stringSplit(String string, String tokens, boolean trimStrings)

Here you can find the source of stringSplit(String string, String tokens, boolean trimStrings)

Description

string Split

License

Open Source License

Declaration

public static String[] stringSplit(String string, String tokens, boolean trimStrings) 

Method Source Code


//package com.java2s;
/*/*from  www . j  a v a2s . com*/
This file is part of JHttpServer.
    
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
JHttpServer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with JHttpServer; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import java.util.*;

public class Main {
    public static String[] stringSplit(String string, String tokens, boolean trimStrings) {
        if (string == null)
            return (null);
        if (string.length() == 0)
            return (new String[0]);

        Vector res = new Vector();
        StringTokenizer stk = new StringTokenizer(string, tokens, false);
        while (stk.hasMoreTokens())
            res.addElement(stk.nextToken());
        String[] res2 = new String[res.size()];
        for (int i = 0; i < res.size(); i++) {
            res2[i] = (String) res.elementAt(i);
            if (trimStrings)
                res2[i] = res2[i].trim();
        }
        return (res2);
    }
}

Related

  1. splitVersion(String version)
  2. splitWithoutEscaped(String str, String sep)
  3. splitWS(String s, boolean decode)
  4. splitws(String val)
  5. stringSplit(String s)
  6. stringSplitter(String string)