【发布时间】:2013-08-06 10:06:11
【问题描述】:
我有一个字符串
string astring="#This is a Section*This is the first category*This is the
second Category# This is another Section";
我想根据分隔符分隔这个字符串。如果我在开头有 # 这将指示部分字符串(字符串 [] 部分)。如果字符串以 * 开头,这将表明我有一个类别(字符串 [] 类别)。 结果我想拥有
string[] section = { "This is a Section", "This is another Section" };
string[] category = { "This is the first category ",
"This is the second Category " };
我找到了这个答案: string.split - by multiple character delimiter 但这不是我想要做的。
【问题讨论】:
-
对我来说看起来像是正则表达式的工作,使用捕获应该在公园散步的组
-
@SimonRapilly 你甚至不需要捕获组。匹配就足够了。
-
确实如此,如果您的答案中有两个正则表达式,但如果您想要一个正则表达式,那么您将需要捕获组
标签: c# asp.net string delimiter