How to Get User Input and allowing more than 256 characters to be entered on .NET Console Application
Posted by Daniel - 2,719 Views
Console Application is good if you want to perform processes without the need of user intervention. Usually automated processes designed to run on schedule. But you can also prompt the user for action if for some reasons you need to do it and it is very simple. All you need to do is utilize the Console.ReadLine command.
This how to article will show you an example of it. The scenario applied in the included demo project is how to prompt the user for keyboard input and how to extend the 256 characters limit. That’s why you see two related processes in the title of this post.
GET USER INPUT. As I said before it’s very simple to get the user input. Declare a string variable then assign Console.ReadLine command to it as shown below:
strInput = Console.ReadLine()
When executed, the application will prompt the user for keyboard input. After the user hit the [Enter] key, the strInput variable will contain characters typed by the user.
Unfortunately, the default limit of characters allowed to be entered is 256 characters. It’s quite reasonable since most of console applications are not designed to handle large amount of user input at a time, but if somehow you need to get more than that limit, following is the trick:
ALLOWING MORE THAN 256 CHARACTERS. The logic is simple. Specify the limit of characters allowed to be entered by the user before calling the Console.ReadLine command. Below are the implementations,
VB.Net Code:
Dim inputStream As Stream = Console.OpenStandardInput(inputBuffer.Length)
Console.SetIn(New StreamReader(inputStream))
strInput = Console.ReadLine()
C# Code
Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
Console.SetIn(new StreamReader(inputStream));
string strInput = Console.ReadLine();
Tips: Just in case you have no idea how to do it , to paste text into the command prompt window you can right click the caption then select [Edit] - [Paste].
Download ReadLine Example (60 KB)
__________________________
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
- Visual Basic.NET, an example of using HTTPWebRequest object
- Resizing image on the fly with ASP.NET using the System.Drawing namespace
Related posts brought to you by Yet Another Related Posts Plugin.
Latest from Programming
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- Free Softwares to help you learn Regular Expression or to enhance your RegEx skill
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
Leave a Reply
Latest Blog Entries
- Sweet Home 3D, a free home design software
- 26x Optical Zoom on a Compact Digital Camera?
- Windows 7 Release Candidate is now available
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- The Lack of Chances is the Source of Poverty, Can we make a different?
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
Categories
Neighbours and Friends
- Anti Teori
- Busby SEO Test Page
- Deny Sri
- Digital Media Convert
- Freeware Maniac
- Oeroek
- RidhoCyber
- Suraja Web
Comments - Thanks Guys :)
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
Marlena Albu: Super Blog, Dude! I am constantly on the watch for new and interesting sites and postings about audio equipment… which is what...
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
Sean: This is a great piece of code and thanks for adding the updates. Sean’s last blog post: Not All Text Message Marketing Is Created...
rodhy: Thank for your code, it very usefull for me. best regard.
Most Popular Entries
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- An example: Using CPort Delphi Component to read data from your cellphone
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
Software Collections
- Sweet Home 3D, a free home design software
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
- TCPView for Windows, Tool to check TCP and UDP Connections on your system
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
Blogging Related Stuff
- Change the WordPress permalink structure to the best format, and yes it’s a little bit scary :D
- Something is wrong, the Google Search Result from my blog looks bad, don’t laugh please :D
- Several tips to reduce Blog Noise, especially when your blog covers more than one niche
- How to remove your indexed pages or even your entire site from Google and Yahoo!

















