字符串分割

2016-02-19 15:35 3 1 收藏

下面是个超简单的字符串分割教程,图老师小编精心挑选推荐,大家行行好,多给几个赞吧,小编吐血跪求~

【 tulaoshi.com - 编程语言 】

  

/**
 * 字符串分割
 *
 * @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/bianchengyuyan/)

来源:http://www.tulaoshi.com/n/20160219/1609945.html

延伸阅读
标签: Web开发
去掉字符串中匹配 的字符串 代码如下: /** * 去掉字符串中匹配 的字符串 * * @author zhujie * @return String regex 要替换的内容 value 字符串 state 替换的内容变成什么 */ public static String toRegex(String regex, String value, String state) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(value); String...
Delphi中的字符串 ——摘自网络 一:各种字符串  字符串是Object Pascal所有数据类型中最有用的类型。许多函数以字符串为传递参数。由于在Delphi中字符串的定义和使用有各种方式,包括Pascal中典型的字符串(String),Delphi支持的长字符串(ANSIString),类似于C语言的字符数组(Array of Char),指向字符的...
标签: Web开发
a href="1.htm"251/a 怎么用JS把251替换为 span style='background-color: #99FF99'251/span [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
SELECT   SUBSTR (T.RPT_ID,                 INSTR (T.RPT_ID,',',1,C.LV)+ 1,                 INSTR (T.RPT_ID,',',1,C.LV + 1)- (INSTR (T.RPT_ID,',',1,C.LV)+ 1)) &n...
标签: ASP
  '*************测字符串长度************** Function CheckStringLength(txt) txt=trim(txt) x = len(txt) y = 0 for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) 255 then '如果是汉字 y = y + 2 else y = y + 1 end if next CheckStringLength = y End Function '************* 截取字符串 ************** f...

经验教程

685

收藏

41
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部