Read a line of string and check its length : Console « Development Class « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Development Class » ConsoleScreenshots 
Read a line of string and check its length
 
using System;

class MainEntryPoint {
    static void Main(string[] args) {
        Console.WriteLine("Type in a string");
        string input;
        input = Console.ReadLine();
        if (input == "") {
            Console.WriteLine("You typed in an empty string");
        else if (input.Length < 5) {
            Console.WriteLine("The string had less than 5 characters");
        else if (input.Length < 10) {
            Console.WriteLine("The string had at least 5 but less than 10 characters");
        }
        Console.WriteLine("The string was " + input);
    }
}

 
Related examples in the same category
1.Echo some stats
2.WriteLine and Write
3.Printing one line of text with multiple statements.
4.Printing multiple lines with a single statement.
5.Printing multiple lines of text with string formatting.
6.Displaying the sum of two numbers input from the keyboard.
7.Change console foreground color and background colorChange console foreground color and background color
8.Clear consoleClear console
9.Set console: title, window size, buffer height and width, cursor positionSet console: title, window size, buffer height and width, cursor position
10.CursorVisible ResetColor SetWindowSize BufferHeight BufferWidth CursorLeft CursorSize CursorTop
11.Use Red and Green from ConsoleColor
12.Beep
13.Beep(200, 300)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.