当前位置:首页 > C#教程 > C#进阶

C#计算每个字符的出现次数

using System;

public class Demo {
   public static void Main() {
      string str = "Website";

      Console.WriteLine("String: "+str);

      while (str.Length > 0) {
         Console.Write(str[0] + " = ");
         int cal = 0;

         for (int j = 0; j < str.Length; j++) {
            if (str[0] == str[j]) {
               cal++;
            }
         }

         Console.WriteLine(cal);
         str = str.Replace(str[0].ToString(), string.Empty);
      }
      Console.ReadLine();
   }
}

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐