2013-06-01 93 views
0

正如你在C#中看到的,一个语句在{}内部的花括号中{ }现在如果我们有一个字符串在[[]]这些内部包含多个字符串。如何获取字符串内[[string]]内的字符串? (C#)

样品输入输出:

string s = "this is the string I am talking about [[and the text inside]] but don't  forget about other [[ones like this]]."; 

string[] insideBrackets; 

insideBrackets[0] will be **and the text inside** 
insideBrackets[1] will be **ones like this** 

顺便说一句我有字符串分割和的indexOf,但他们没有工作,以及我想要的。 谢谢无论谁回答,希望这会得到大拇指,因为它是一个很好的问题:)

+0

您可以使用'Regex'来获取括号内的字符串。 –

回答

9

您可以使用Regex为此。

string s = "this is the string I am talking about [[and the text inside]] but don't  forget about other [[ones like this]]."; 

var insideBrackets = Regex.Matches(s, @"\[\[(.+?)\]\]").Cast<Match>() 
         .Select(m => m.Groups[1].Value) 
         .ToArray(); 
+1

就像一个魅力伴侣,谢谢 – Pedrum

相关问题