日期:2014-05-17  浏览次数:20492 次

怎么从字符串中截取""中间的字符?
比如我有一个字符串:
string str = "[abc]{"123")[fddsds].."sdaaa"[zzz]+/";
获取[abc]很简单,用str.Substring(str.IndexOf('['), str.IndexOf(']') + 1);就可以了
但是怎么从字符串中获取"123"?
听说可以用正则或者IndexOf,求解答。

------解决方案--------------------
try...

C# code

string str = "[abc]{\"123\")[fddsds]..\"sdaaa\"[zzz]+/";
Regex reg = new Regex(@"""([^""]+)""");
MatchCollection mc = reg.Matches(str);
foreach (Match m in mc)
{
    richTextBox2.Text += m.Groups[1].Value + "\n";
}
/*-----输出-----
123
sdaaa
*/