String s="fdsaf,fdsew,fwio,oijf";
StringTokenizer st=new StringTokenizer(s,",");//其中逗号可用任意多个其它字符代替,如",;'"等
String str=null;
while(st.hasMoreToken()){
  str=st.nextToken();
}

解决方案 »

  1.   

    public String[] split(CharSequence input, int limit) {
            int index = 0;
            boolean matchLimited = limit > 0;
            ArrayList matchList = new ArrayList();
            Matcher m = matcher(input);        // Add segments before each match found
            while(m.find()) {
                if (!matchLimited || matchList.size() < limit - 1) {
                    String match = input.subSequence(index, m.start()).toString();
                    matchList.add(match);
                    index = m.end();
                } else if (matchList.size() == limit - 1) { // last one
                    String match = input.subSequence(index, 
                                                     input.length()).toString();
                    matchList.add(match);
                    index = m.end();
                }
            }        // If no match was found, return this
            if (index == 0)
                return new String[] {input.toString()};        // Add remaining segment
            if (!matchLimited || matchList.size() < limit)
                matchList.add(input.subSequence(index, input.length()));        // Construct result
            int resultSize = matchList.size();
            if (limit==0)
                while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
                    resultSize--;
            String[] result = new String[resultSize];
            return (String[])matchList.subList(0, resultSize).toArray(result);
        }
      

  2.   

    public String[] split(CharSequence input) {
            return split(input, 0);
        }JDK上的源码
      

  3.   

    split的参数是两个,都是字符串,返回是数组
    split(CharSequence input)??不明白啊。
      

  4.   

    String就是一个CharSequence,split用的是正则表达,请参考java.util.regex.Pattern,
      

  5.   

    不需要专门写split函数了,我以前也写过。后来发现java已经有了解决办法
    用StringTokenizer这个类来实现,例:
    /*
     * Created on 2004-7-5
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package temp;import java.util.StringTokenizer;/**
     * @author wx
     * 
     * TODO To change the template for this generated type comment go to Window -
     * Preferences - Java - Code Style - Code Templates
     */
    public class Temp {    public static void main(String[] args) {
            String str = "one#tow#three#four";
            StringTokenizer st = new StringTokenizer(str, "#");
            while (st.hasMoreTokens()) {
                System.out.println(st.nextToken());
            }
        }
    }