c#中单独的半冒号分隔字符串 [英] Separate semi colon separated string in c#

查看:381
本文介绍了c#中单独的半冒号分隔字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,

我有一个文本框。

其中一些条目像

textbox.text = Tendulkar,Sachin( sh); Dhoni,MS(msd); Sehwag,Virender(viru); D'Souza,Tim(tdsc)



我想要一个字符串数组像(srt,msd,viru,tdsc)这样的值。

我想我们首先必须绕过(';')并得到一个结果数组。

然后用('(')和(')')拆分。

我认为另一个是for循环。



我怎么能得到这个?

如果你好帮我的话,感激不尽。



谢谢

Akshay

Hey All,
I have a textbox.
In that some entries are made like
textbox.text = Tendulkar,Sachin(srt);Dhoni,MS(msd);Sehwag,Virender(viru);D'Souza,Tim(tdsc)

I want an array of string which will have values like (srt,msd,viru,tdsc).
I guess we will first have to go around splitting by (';') and get a result array set of this.
and then split with ('(') and (')').
A for loop inside another is what i guess.

How can i get this??
Appreciate if u cud help me out.

Thanks
Akshay

推荐答案

更简单的方法是使用正则表达式:

Easier way is to use a Regex:
string s = "Tendulkar,Sachin(srt);Dhoni,MS(msd);Sehwag,Virender(viru);D'Souza,Tim(tdsc)";
Regex reg = new Regex(@"(?<=\().+?(?=\))");
MatchCollection matches = reg.Matches(s);
List<string> separated = new List<string>();
foreach (Match m in matches)
    {
    separated.Add(m.Value);
    }


这篇关于c#中单独的半冒号分隔字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆