假设有一段文字如下:
string str = @"stackoverflow(
stack:stackoverflow)overstackflow(
over:stackoverflow )";
我想要粗体字段。 我想我必须在文本中找到“(”和“:”并获取它们之间的文本。不是吗?
有什么建议吗?
最佳答案
也许使用普通的 string
方法:
IList<String> foundStrings = new List<String>();
int currentIndex = 0;
int index = str.IndexOf("(", currentIndex);
while(index != -1)
{
int start = index + "(".Length;
int colonIndex = str.IndexOf(":", start);
if (colonIndex != -1)
{
string nextFound = str.Substring(start, colonIndex - start);
foundStrings.Add(nextFound);
}
currentIndex = start;
index = str.IndexOf("(", currentIndex);
}
关于c# - 在严格的文本中获取文本的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13968684/