My scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :)

Breaking

Thursday, September 29, 2022

Golang - Reading multiline input

Since software inception, we always interact with user to ask their input and pass it along to the software to process. Golang provides multiple ways to read input from standard input, there are packages like bufio, ioutil, fmt and many others which are used to accomplish the same ask. 
        When working with standard input (usually it's terminal) we often stumble-upon the scenario where we read which includes the new line as well. In happy world, Input ends when user press Enter but not always. In Golang world, by tweaking input reader logic, we can easily achieve that and that's the topic for today to snippet around. 

--

Output:
go run 36-reading-multiline-user-input.go
Enter Multiline Input: this is line1
> this is line2
> line3
>
Input is: [this is line1 this is line2 line3]
No of lines in input: 3

Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group

No comments:

Post a Comment

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.