读书人

C# 标点符号在字符串中出现的位置解决

发布时间: 2012-06-09 17:16:42 作者: rapoo

C# 标点符号在字符串中出现的位置
字符串“xxxxxx,xxxxxxxx,xxxxxxxx。xxxxxxxx。xxxxxxxxx;xxxxx!xxxxxx!”

如何获取 2个逗号 2个句号 1个分号 和 2个叹号 在字符串中的位置,分别是多少?

[解决办法]

C# code
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);} 

读书人网 >C#

热点推荐