代码期间,把代码过程经常用的内容做个珍藏,下边代码是关于C#的String.Split 分割字符串用法详解的代码,应该对码农们有些用途. 1) public string[] Split(params char[] separator)2) public string[] Split(char[] separator, int count)3) public string[] Split(char[] separator, StringSplitOptions options)4) public
string.split(s[, sep[, maxsplit]]) Return a list of the words of the string s. If the optional second argument sep is absent or None, the words are separated by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed). If th
知识补充 String的split方法支持正则表达式: 正则表达式\s表示匹配任何空白字符,+表示匹配一次或多次. 有了以上补充知识,下面的内容就很好理解了. 一.待分割字符串 待分割字符串为如下: String str = "a b c d e f g" 其中,字符串中的的空白分别为:单个空格,多个空格,tab制表符. 二.使用一个或多个空格分割字符串 正确代码如下: String [] arr = str.split("\\s+"); for(String ss