zoukankan      html  css  js  c++  java
  • 去除重复的字符

    1. static public void DeleteRepeatChar(string s){
    2. Dictionary<char, int> d = new Dictionary<char, int>();
    3. foreach (var c in s){
    4. int num = 0;
    5. if (d.TryGetValue(c, out num)){
    6. d[c] += 1;
    7. Console.WriteLine(c);
    8. }else{
    9. d[c] = 1;
    10. }
    11. }
    12. string strs = "";
    13. foreach (var str in d.Keys){
    14. strs += str;
    15. }
    16. Console.WriteLine(strs);
    17. }
    18. static string AcceptmultiLineChars() {
    19. ConsoleKeyInfo cki;
    20. Console.TreatControlCAsInput = true;//防止Ctrl+C复制
    21. Console.WriteLine("Press the CTRL+Enter key to quit: ");
    22. string result = string.Empty;
    23. do {
    24. cki = Console.ReadKey();
    25. if (cki.Key == ConsoleKey.Enter) {
    26. result += System.Environment.NewLine;//如果输入回车,则加入换行标志
    27. Console.SetCursorPosition(0, Console.CursorTop + 1);//光标下移一行
    28. }
    29. result += cki.KeyChar;
    30. } while (cki.Key != ConsoleKey.Enter || (cki.Modifiers & ConsoleModifiers.Control) == 0);//按Ctrl+Enter退出
    31. return result;
    32. }
    33. static void Main(string[] args){
    34. string s = AcceptmultiLineChars();
    35. DeleteRepeatChar(s);
    36. }





  • 相关阅读:
    屏幕取色器colorspy
    js监控按键
    修改硬件信息小工具
    C#SendKeys的用法
    错误分析:程序集未标记为可序列化
    C#xml反序列化
    office2010激活工具
    截图软件
    C#画图
    .net中SQL防注入代码
  • 原文地址:https://www.cnblogs.com/xiejunzhao/p/6421995.html
Copyright © 2011-2022 走看看