c# 查询字符串内有多少个指定字符!
2012-02-16 18:53
190 查看
C#计算字符串中有多少个“a”
first:
using System.Text;
using System.Text.RegularExpressions;
string a = "adfdf:adfa:afafwer:";
Regex rg = new Regex(":");
MatchCollection mc = rg.Matches(a);
Console.WriteLine(string.Format("Count of @a :{0}", mc.Count));
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("这是个计算字符串中含有多少/"a/"的程序"); Console.WriteLine("请输入字符串"); string s1 = Console.ReadLine(); //int x = s1.IndexOf("a"); int count = 0; int startIndex = 0; while (true) { int y = s1.IndexOf("a", startIndex); if (y != -1) { count++; startIndex = y + 1; } else { break; } } Console.WriteLine("/"a/"在字符串中出现了{0}次", count); Console.ReadLine(); } } }
first:
using System.Text;
using System.Text.RegularExpressions;
string a = "adfdf:adfa:afafwer:";
Regex rg = new Regex(":");
MatchCollection mc = rg.Matches(a);
Console.WriteLine(string.Format("Count of @a :{0}", mc.Count));
相关文章推荐
- c# 查询字符串内有多少个指定字符!
- C#中查询字符串中是否包含指定字符/字符串,使用IndexOf还是Contains?
- C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?
- C#中查询字符串中是否包含指定字符/串,使用IndexOf还是Contains?
- C#新手入门代码 在string字符串中找到指定字符的最大,最小索引值
- C#去掉字符串头尾指定字符
- 【转载】C# 字符串截取指定长度的中文字符--精点
- asp.net 中查询字符串中是否包含指定字符/串
- C#下按照指定字符进行字符串分割
- C# 关于字符串中 符合正则表达式的指定字符的替换的方法
- 通过指针对字符串进行查询并且替换其中的指定字符
- 查询文件中包含多少个指定的字符串
- C# 中如何将List<string>里的集合转换成字符串并按指定的字符进行分隔?
- LotusScript查询指定字符在字符串中的位置
- C#编程入门--将指定字符串中的汉字转换为拼音缩写,其中非汉字保留为原字符
- 字符截取 , 截取指定字符串前后各截取多少个字
- 数组和字符串操作(C#) 1、从字符串中删除指定字符
- C#去掉字符串头尾指定字符
- js查询字符串是否包含指定字符的函数indexOf
- C#中,删除字符串中的指定字符的简便方法