CMD中单行多个输入 [英] Multiple inputs in single line in CMD

查看:67
本文介绍了CMD中单行多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Console.ReadLine方法来获取输入。但是,必须按ENTER键才能接受输入,并使托架显示在NEWLINE上。

I'm using Console.ReadLine method to take inputs. But, have to press ENTER for it to accept the input and it makes the carriage to appear on NEWLINE.

我试图在命令提示符下单行输入多个输入而不移动托架到NEWLINE。

I am trying to take multiple inputs in single line in command prompt without carriage being moved to NEWLINE.

或者,有什么方法可以删除LineFeed吗?

Or, is there any way that I could remove LineFeed?

例如:

Console.WriteLine("ColA      ColB")
a = Console.ReadLine
Console.Write("          ")
b = Console.ReadLine

显示为:

ColA       ColB

ColA        ColB

a            b

a             b

推荐答案

 您可以尝试如下。 使用Console.CursorTop属性将光标向上移动到最后一行,然后写入(a)输入和正确的空格数。 这将把光标定位在第二个"列"。

 You can try it like below.  Use the Console.CursorTop property to move the cursor back up to the last line and then Write the (a) input and the correct number of spaces.  That will position the cursor at the second "column".

    Sub Main()
        Dim a, b As String

        Console.WriteLine("ColA      ColB")
        a = Console.ReadLine

        Console.CursorTop -= 1 'set the cursor back to the last row

        Console.Write(a & New String(" "c, 10 - a.Length)) 're-write (a) and the correct number of spaces
        b = Console.ReadLine

        Console.WriteLine()
        Console.WriteLine("You gave this input...")
        Console.WriteLine(a & New String(" "c, 10 - a.Length) & b)
        Console.ReadKey()
    End Sub


这篇关于CMD中单行多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆