下面是个超简单的字符串分割教程,图老师小编精心挑选推荐,大家行行好,多给几个赞吧,小编吐血跪求~
【 tulaoshi.com - 编程语言 】
/**(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
* 字符串分割
*
* @author
* @param str java.lang.String 要分割的字符串
* @param sp java.lang.String 需要被替换的子串
* @return 替换之后的字符串
* @return 分割失败,返回null
*/
public static String[] Split(String str, String sp)
{
StringTokenizer st = new StringTokenizer(str, sp);
String strSplit[];
try
{
int stLength=st.countTokens();//获取分割后的数量
if(stLength=1)
{
return null;
}
strSplit=new String[stLength];
int i=0;
while (st.hasMoreTokens())
{
strSplit[i]=st.nextToken().toString();
i++;
}
}
catch(Exception e)
{
return null;
}
return strSplit;
}
来源:http://www.tulaoshi.com/n/20160219/1609945.html