A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 782385854 中级黑马   /  2013-10-18 09:52  /  1383 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 782385854 于 2013-10-19 20:29 编辑

string str ="h,e,l,l,o,w,o,r,l,d";;
            string[] arry = str.Split(',');
            Dictionary<string, int> st = new Dictionary<string, int>();
            foreach (string w in arry)
            {
                if (st.ContainsKey(w))
                {
                    st[w] += 1;
                }
                else
                {
                    st[w] = 1;
                }
            Console.WriteLine(w);
            }

            Console.ReadKey();

评分

参与人数 1技术分 +1 收起 理由
茹化肖 + 1 虽然大家没帮上什么,但是自己思考也给分哦.

查看全部评分

9 个回复

倒序浏览
出现的次数怎么算
回复 使用道具 举报
            int count = 0;  为什么出现错误呢,
回复 使用道具 举报
            int count = 0;
            string str ="h,e,l,l,o,w,o,r,l,d";;
            string[] arry = str.Split(',');
            Dictionary<string, int> st = new Dictionary<string, int>();
            foreach (string w in arry)
            {
                if (st.ContainsKey(w))
                {
                    st[w] += 1;
                }
                else
                {
                    st[w] = 1;
                }
                for (int i = 0; (i =str.IndexOf(w,i))>=0; i++)
                {
                    count++;
                }
            Console.WriteLine("{0}{1}",w,count);
            }

            Console.ReadKey();

评分

参与人数 1技术分 +1 收起 理由
追溯客 + 1

查看全部评分

回复 使用道具 举报
已解决,封贴
回复 使用道具 举报
string str ="h,e,l,l,o,w,o,r,l,d";;

~~~带来两个“;”
回复 使用道具 举报
haxyek 金牌黑马 2013-10-19 17:58:28
7#
说学逗唱,样样都会啊~
回复 使用道具 举报
string str = "W,e,l,c,o,m,e,t,o C,h,i,n,a,w,o,r,l,d"; ;
            string[] arry = str.Split(',');
            Dictionary<string, int> st = new Dictionary<string, int>();
            foreach (string w in arry)
            {
                if (st.ContainsKey(w))
                {
                    st[w] += 1;
                }
                else
                {
                    st[w] = 1;
                }
            }
            foreach (var kv in st)
            {
                Console.WriteLine(string.Format("{0}:{1}", kv.Key, kv.Value));
            }

            Console.ReadKey();

评分

参与人数 1技术分 +1 收起 理由
追溯客 + 1

查看全部评分

回复 使用道具 举报
haxyek 发表于 2013-10-19 17:58
说学逗唱,样样都会啊~

老师何出此言呢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马