English 中文(简体)
阅读一组来自青少年投入的特性
原标题:reading a set count of characters from the console input stream

I m trying to make something like a textbox for a console application, how to limit the Console.In to only read a defined count of characters from user inputs ?

EDIT

我可以浏览<代码>Readkey( loop-way,即仍然需要与该盒进行互动,例如使用箭钥匙进行航行,留下了一种权利,Del或后天,以吸收投入和一些关键因素进行验证。 <代码>ReadKey正在将这些钥匙作为“(空间)”加以印刷,并可能依靠依赖自<>易燃<<>>>后压力多少钥匙(在这一项目中,我们需要过度搭售!)

想像在某个特定地点从缓冲区读到的东西,并在达到顶峰时将 cur子放在另一个地点。 能够这样做?

我的机会是什么? 确实需要你的帮助

问题回答

你可以限制康索尔。 ReadLine()等 但是,你可以选择康索尔。 例如,阅读和验证其中的投入。

我很奇怪的是,如果能够做到这一点,我就提出:

    private static string ReadBox(int maxLen)
    {
        var sb = new StringBuilder();
        int pos = 0;
        bool done = false;      
        int start = Console.CursorLeft;

        while (!done)
        {
            var ki = Console.ReadKey(true);

            switch (ki.Key)
            {
                case ConsoleKey.Enter:
                    done = true;
                    break;

                case ConsoleKey.Delete:
                    // todo
                    break;

                case ConsoleKey.Backspace:
                    if (pos > 0)
                    {
                        pos -= 1;
                        sb.Remove(pos, 1);
                    }                                
                    break;

                case ConsoleKey.LeftArrow:
                    if (pos > 0) pos -= 1;
                    break;

                case ConsoleKey.RightArrow:
                    if (pos < sb.Length) pos += 1;
                    break;

                default:
                    if (ki.KeyChar >=    )  // simple filter
                    {
                        sb.Insert(pos, ki.KeyChar);
                        pos += 1;
                    }
                    break;
            }
            Console.CursorLeft = start;
            Console.Write(sb.ToString());
            Console.CursorLeft = start + pos;                
        }
        return sb.ToString();
    }

请注意,我们实际上没有使用哥索尔。 在此缓冲地带,它被绕过。 奥赫特和我从头开始就留下了大事。 但是,你可以轻易执行。

但是,如果你严肃对待这一类型的国际调查,我会看一看一个曲线图书馆,如,这个图书馆是。 但我想起莫诺的话,我甚至不敢肯定,如果它将在网络上运行。 搜索。

可在休息和通过<条码>上打电话,以防止重复。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签