做一个操作界面,提示操作:输入文件名、输入所查找的字符或字符串等; 显示出查找到的数目

2024-12-15 08:59:13
推荐回答(1个)
回答1:

遍历要查找的字符在字符串中出现的次数! C#程序的实例:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string str = "AUIFUIVBNUEGFJKEI";
int all = 0;//计数器
for (int i = 0; i < str.Length; i++)
{
//每次取出一个字符
char c = str[i];
if (c == 'a' || c == 'A')
{
all++;
}
if (c == 'i' || c == 'I')
{
all++;
}
if (c == 'o' || c == 'O')
{
all++;
}
if (c == 'u' || c == 'U')
{
all++;
}
if (c == 'e' || c == 'E')
{
all++;
}
}
Console.WriteLine("总共有{0}个元音",all);
}
}
}