写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。
第一行输入一个有字母和数字以及空格组成的字符串,第二行输入一个字符。
输出输入字符串中含有该字符的个数。
ABCDEF A
1
sing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { string str = Console.ReadLine().ToLower(); //string str=""""; string str2 = Console.ReadLine().ToLower(); char[] c = str.ToCharArray(); int num = 0; for (int i = 0; i < c.Length; i++) { if (str2 == c[i].ToString()) { num++; } } //string[] a = str.Split(‘ ‘); //int b = a[a.Length - 1].Length; Console.WriteLine(num); Console.ReadKey(); } } }
原文:https://www.cnblogs.com/mingqi-420/p/12532145.html