日期:2014-05-17 浏览次数:20495 次
string str = "@你@我@他@所有人";
string[] ss = str.Split(new char[]{'@'}, StringSplitOptions.RemoveEmptyEntries);
------解决方案--------------------
> "@你@我@他@所有人".Split('@')
string[5] { "", "你", "我", "他", "所有人" }
> "@你@我@他@所有人".Split(new char[] { '@' },StringSplitOptions.RemoveEmptyEntries)
string[4] { "你", "我", "他", "所有人" }
------解决方案--------------------
string str = "@你@我@他@所有人";
string[] arr = str.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
------解决方案--------------------
new char['@']
=>
new char[] {'@'}
------解决方案--------------------
你应该注意Split的第二个参数“StringSplitOptions.RemoveEmptyEntries”
------解决方案--------------------
正则:@(.+?)\s
代码:
string str = "@你 对你说@我 对自己说@他 对他说@所有人 这是对所有人说";
System.Text.RegularExpressions.Regex regex=new System.Text.RegularExpressions.Regex("@(.+?)\\s");
System.Text.RegularExpressions.MatchCollection collection = regex.Matches(str);
for(int i=0;i<collection.Count;i++)
{
MessageBox.Show(collection[i].Groups[1].Value);
}
------解决方案--------------------
string s="@你 对你说@我 对自己说@他 对他说@所有人 这是对所有人说";
string [] a=s.Trim('@').Split('@');
int count=a.Length;
string [] b =new string [count];
for(int i=0;i<count;i++)
{
b[i]=a[i].Split(' ')[0];
}