<分区>
string text = "{hello|{hi}} {world}";
实际上我想要给定字符串中的'{'和'}'每个出现位置
请帮帮我... 提前致谢!
<分区>
string text = "{hello|{hi}} {world}";
实际上我想要给定字符串中的'{'和'}'每个出现位置
请帮帮我... 提前致谢!
最佳答案
您可以使用 Regex.Matches。它将搜索所有被 '|' 分割的字符串在句子中。 您可以将所有字符串及其索引添加到 Dictioanry。
string pattern = "{|}";
string text = "{hello|{hi}} {world}";
Dictionary<int, string> indeces = new Dictionary<int, string>();
foreach (Match match in Regex.Matches(text, pattern))
{
indeces.Add(match.Index, match.Value);
}
结果是:
0-{
7-{
10-}
11-}
13-{
19-}
关于c# - 如何在给定的字符串中找到多次出现的特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18118658/