using System;public class SplitTest {
public static void Main() { string words = "this is a list of words, with: a bit of punctuation."; string [] split = words.Split(new Char [] {' ', ',', '.', ':'}); foreach (string s in split) { if (s.Trim() != "")
Console.WriteLine(s);
}
}
}
public static void Main() { string words = "this is a list of words, with: a bit of punctuation."; string [] split = words.Split(new Char [] {' ', ',', '.', ':'}); foreach (string s in split) { if (s.Trim() != "")
Console.WriteLine(s);
}
}
}
解决方案 »
- VS2010 添加数据源 “使用SQL Server身份验证”失败
- Winform + SQLite数据库开发遇到问题!求助
- C# webbrowser <A> 鼠标点击可以 InvokeMember("click") 不行
- 关于对话框的OpenDialog方法
- dataset与Windows服务
- 奇怪啊!! 前端 js 和 后端cs 控制html属性的问题!
- 如何把酷狗歌词解码到txt文档中啊
- 高手来看看这个程序怎么改才正确???
- c# 中语句的写法,这个意思?
- 分值不高,但提一问:静态数据被类实力访问????(BUG???????)
- 是否要放入数组中?还是其它的什么里面,方便查找(应用开发)
- 用VS2005开发PDA程序时连接SQL Server2000,出现错误,急!
搂住如果有c#入门经典的话
参考608页
有详细的介绍
{
System.Collections.Specialized.StringCollection sc = new StringCollection();
//string Str = "AA 你好! BB";
string tmp = "";
for (int i = 0; i < Str.Length; i++)
{
if (Str[i].ToString() != " ")
{
tmp += Str[i];
}
else
{
if (tmp != "")
sc.Add(tmp); tmp = "";
} if (i == Str.Length - 1 && tmp != "")
{
sc.Add(tmp);
}
}
return sc;
}
测试通过string Str = "AA ddddd 你好! BB";
StringCollection sc = MyClass.GetSplit(Str);string Str = " AA ddddd 你好! BB";
StringCollection sc = MyClass.GetSplit(Str);string Str = "AA ddddd 你好! BB ";
StringCollection sc = MyClass.GetSplit(Str);
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;namespace StringOperator
{
class Program
{ static void Main(string[] args)
{
string str = "AA 你好! BB";
Regex reg =new Regex( @"(?<content>[\S]+)");
if (reg.IsMatch(str))
{
foreach (Match match in reg.Matches(str))
{
Console.WriteLine(match.Groups["content"].Value);
}
}
Console.ReadLine();
}
}
}