zoukankan      html  css  js  c++  java
  • 查询字符串中字母出现的个数

    /*查询字符串中字母出现的个数*/
                string str = " Welcom Hello World";
                Dictionary<char, int> dc = new Dictionary<char, int>();
                for (int i = 0; i < str.Length; i++) //遍历字符串的长度
                {
                    if (str[i] == ' ')
                    {
                        continue;
                    }
                    if (!dc.ContainsKey(str[i]))
                        {
                        dc.Add(str[i], 1);
                    }
                    else
                    {
                        dc[str[i]]++;
                    }
                }
                foreach (KeyValuePair<char,int> kv in dc)
                {
                    Console.WriteLine("{0},{1}", kv.Key,kv.Value);
                }
                Console.ReadKey();

  • 相关阅读:
    ubuntu18.04安装g2o
    akka学习
    spark学习记录-2
    spark学习记录-1
    c++ string需要注意的地方
    clion server激活地址
    【转】c++面试基础
    c++反射概念-简单介绍
    死锁的理解
    c++ 反射类型
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5386695.html
Copyright © 2011-2022 走看看