查看第二个參数在第一个參数中出现的次数
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace testfour { class Program { static void Main(string[] args) { MyClass myclass = new MyClass(); int num = myclass.CountChar("fdfdfdfcxvcxcdfsdffvcdv", 'd'); Console.WriteLine(num); Console.Read(); } } class MyClass { public int CountChar(String str,char ch) { return str.Split(ch).Length - 1; } } }