none
Multiple inputs in single line in CMD RRS feed

  • Question

  • 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.

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

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

    For example:

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

    To be appeared as:

    ColA        ColB

    a             b

    Saturday, February 10, 2018 3:44 PM

All replies

  •  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
    


    If you say it can`t be done then i`ll try it

    Saturday, February 10, 2018 4:13 PM
  • Yea, but the Enter key is meant as Enter, not something as move or whatever you want to assign to it. 

    What you ask is like saying "I want to walk upside down but still use my feets to move"

    I know there are no foolish questions, however those who makes them are mostly ...............................

    :-)


    Success Cor

    Saturday, February 10, 2018 5:08 PM
  • See:

    Apparently the functions described there must be used by Platform Invoke.

    Also see Console Class. That is a .Net class. At least one of the samples uses Platform Invoke for some functions but you can use .Net for much of what can be done for consoles.



    Sam Hobbs
    SimpleSamples.Info

    Saturday, February 10, 2018 10:49 PM
  • Yea, but the Enter key is meant as Enter, not something as move or whatever you want to assign to it. 

    Although it seems strange for most Windows programmers, consoles can be used for rather sophisticated formatted I/O.


    Sam Hobbs
    SimpleSamples.Info

    Saturday, February 10, 2018 10:51 PM
  • Hi M. Waqas,

    You can also use String.PadRight Method (Int32) to add space in string.

    Console.WriteLine("ColA     ColB")
            Dim a = Console.ReadLine().PadRight(10)
            Console.CursorTop -= 1
            Console.Write(a)
            Dim b = Console.ReadLine()
            Console.WriteLine()
            Console.ReadKey()

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 12, 2018 7:22 AM
    Moderator