C#中split用法
来源:互联网 发布:淘宝啮齿一号 编辑:程序博客网 时间:2024/05/17 22:34
1、用字符串分隔:
using System.Text.RegularExpressions;
string str="aaajsbbbjsccc";
string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
foreach (string i in sArray) Response.Write(i.ToString() + "<br>");
输出结果:
aaa
bbb
ccc
2、用多个字符来分隔:
string str="aaajbbbscccjdddseee";
string[] sArray=str.Split(new char[]{'j','s'});
foreach(string i in sArray) Response.Write(i.ToString() + "<br>");
输出结果:
aaa
bbb
ccc
ddd
eee
3、用单个字符来分隔:
string str="aaajbbbjccc";
string[] sArray=str.Split('j');
foreach(string i in sArray) Response.Write(i.ToString() + "<br>");
输出结果:
aaa
bbb
ccc
Split重载方法:
1.public string[] Split(params char[] separator);
2.public string[] Split(char[] separator, int count);
3.[ComVisible(false)]
public string[] Split(char[] separator, StringSplitOptions options);
4.[ComVisible(false)]
public string[] Split(string[] separator, StringSplitOptions options);
5.[ComVisible(false)]
public string[] Split(char[] separator, int count, StringSplitOptions options);
6.[ComVisible(false)]
public string[] Split(string[] separator, int count, StringSplitOptions options);
StringSplitOptions options:前后有空项时是否返回空项
如:/2008/1/1 以‘/’分割
1)StringSplitOptions.None 返回 空 2008 1 1
2)StringSplitOptions.RemoveEmptyEntries 返回 2008 1 1
int count:返回分割的项目数
- C#中split用法
- C#中split用法
- C#中Split用法~
- C#中Split用法
- C#中Split用法
- C#中Split用法
- C#中Split用法
- C#中Split用法~
- C#中Split用法~
- C#中Split用法~
- C#中split用法
- C#中Split用法
- C#中Split用法
- C#中Split用法
- C#中Split用法
- C#中Split用法
- C#中Split用法~
- C#中Split用法
- 主攻方向 --> Swing
- csdn的开始
- 找零时刻
- 软件史上最严重的十个Bug
- 自定义Button组件
- C#中split用法
- Win32汇编入门Hello World程序
- cpu
- 设计模式观察-Singleton
- pku1160 Post Office 解题报告
- brewmp的优势
- XP下安装Ubuntu10.04双系统
- 小乔爱问
- 计算机达人成长之路(6)