分割字符串与获取子字符串
2008-11-14 20:36
148 查看
string类提供一个方法Split用以切割字符串,此方法返回一个包含所有分割子字符串的数组对象,可以经过数组取得所有分割的子字符串, string result = ""; string myString = "To comment on this book,send email to:tim@pie.com.tw "; char[] splitChar=new char[]{',',':','@','.',' '}; foreach (string subString in myString.Split(splitChar)) { result = result + subString + "/n"; } Console.WriteLine(result); Console.ReadKey();获取子字符串:Substring() string result = ""; string myString = "To comment on this book,send email to:tim@pie.com.tw "; result=myString.Substring(24); Console.WriteLine("第24个字符以后的子字符串:{0}",result);//从第0开绐算第24个字符以后, result=myString.Substring(29,5); Console.WriteLine("第29以后5个字符的子字符串:{0}",result); Console.ReadLine(); 结果:send email to:tim@pie.com.tw email
相关文章推荐
- c split 函数 分割字符串 获取指定index的子字符串
- js正则获取图片的src属性及正则分割一个字符串
- Java-从一个字符串获取子字符串
- 获取字符串中的子字符串
- 分割字符串的方法(获取某个字符后的字符串)
- C++]_[获取Utf8字符串的字符个数和子字符串]
- GetCommandLine 获取当前进程的命令行字符串 对字符串进行分割
- perl语言:分割路径字符串,获取文件名
- java.lang.string.split作用:分割字符串为子字符串
- [C++]_[获取Utf8字符串的字符个数和子字符串]
- PHP中字符串分割、获取子串以及向文本框中添加值
- shell高效获取分割字符串
- 获取以指定分割符分割的字符串
- [C++]_[获取Utf8字符串的字符个数和子字符串]
- SQL Server获取下一个编码字符串的实现方案分割和进位
- 临时搞两天VC,在VC里如何获取当前程序的名字和路径以及如何分割字符串
- [C++]_[获取Utf8字符串的字符个数和子字符串]
- 获取报告 Stream转string,利用字符串分割转换成DataTable
- 001_013 Python 字符串分割 访问子字符串
- 如何在T-SQL中获取逗号分割的字符串数据中的元素?