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();
   }
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265921.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论