游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3319|回复: 1

Dicionary如何可以防止重?

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2007-12-12 00:03:00 | 显示全部楼层 |阅读模式
            //Read the text
            string text = "丁丁是??人才";
            
            //string text = System.IO.File.ReadAllText("FileContainingAllMyGameText.txt");

            // Remove duplicates
            Dictionary<char, bool> characters = new Dictionary<char, bool>();
            foreach (char c in text)
            {   
                characters.Add(c, true);//重??r?一行??鲥e
            }
            // Write XML
            foreach (char c in characters.Keys)
            {   
                Console.WriteLine("<CharacterRegion>");   
                Console.WriteLine("    <Start>&#{0};</Start>", (int)c);   
                Console.WriteLine("    <End>&#{0};</End>", (int)c);   
                Console.WriteLine("</CharacterRegion>");
            }

            base.Initialize();

20

主题

451

帖子

470

积分

中级会员

Rank: 3Rank: 3

积分
470
发表于 2008-2-20 00:13:00 | 显示全部楼层

Re:Dicionary如何可以防止重?

用characters.ContainsKey函数检测
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 06:05

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表