C# 标点符号在字符串中出现的位置
字符串“xxxxxx,xxxxxxxx,xxxxxxxx。xxxxxxxx。xxxxxxxxx;xxxxx!xxxxxx!”
如何获取 2个逗号 2个句号 1个分号 和 2个叹号 在字符串中的位置,分别是多少?
[解决办法]
string s = "xxxxxx,xxxxxx,xxxxxxxx。xxxxxxxx。xxxxxxxxx;xxxxx!xxxxxx!";List<int> position = new List<int>();int index = -1;while ((index = s.IndexOf(',', index + 1)) >= 0){ position.Add(index);}