zoukankan      html  css  js  c++  java
  • 读取控制台字符串

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleUtilities
    {
        class AcceptMutilLine
        {
            static string acceptmultiLine()
            {
                ConsoleKeyInfo cki;
                Console.TreatControlCAsInput = true;//防止Ctrl+C复制
                Console.WriteLine("Press the F10 key to quit: \n");
                string result = string.Empty;
                do
                {
                    cki = Console.ReadKey();
                    result += cki.KeyChar;
                    if (cki.Key == ConsoleKey.Enter)
                    {
                        result += System.Environment.NewLine;//如果输入回车,则加入换行标志
                    }
                } while (cki.Key != ConsoleKey.F10);//按F10退出
                return result;
            }

            public static void Func(string[] args)
            {
                string s = acceptmultiLineChars2();
                Console.WriteLine(s);
                Console.ReadLine();
            }

            static string acceptmultiLineChars2()
            {
                ConsoleKeyInfo cki;
                Console.TreatControlCAsInput = true;//防止Ctrl+C复制
                Console.WriteLine("Press the CTRL+Enter key to quit: \n");
                string result = string.Empty;
                do
                {
                    cki = Console.ReadKey();
                    if (cki.Key == ConsoleKey.Enter)
                    {
                        result += System.Environment.NewLine;//如果输入回车,则加入换行标志
                        Console.SetCursorPosition(0, Console.CursorTop + 1);//光标下移一行
                    }
                    result += cki.KeyChar;
                } while (cki.Key != ConsoleKey.Enter || (cki.Modifiers & ConsoleModifiers.Control) == 0);//按Ctrl+Enter退出
                return result;
            }
        }
    }

  • 相关阅读:
    Flask之threading.loacl方法
    websocket之简易聊天室
    websocket介绍
    Flask之jinja2模板语言
    Flask之基础
    Linux之项目的部署
    Linux之nginx负载均衡
    Linux之nginx
    Linux之redis-cluster
    Linux之redis-sentinel
  • 原文地址:https://www.cnblogs.com/ShaYeBlog/p/2410197.html
Copyright © 2011-2022 走看看