首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-06-09 
C# 标点符号在字符串中出现的位置字符串“xxxxxx,xxxxxxxx,xxxxxxxx。xxxxxxxx。xxxxxxxxxxxxxx!xxxxxx!”如

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);} 

热点排行