CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Posts
    1

    Console string manipulating

    Hey, this may sound nooby, I'd like to know how to correctly manipulate Console.ReadLine(); .
    Code:
                switch (Console.ReadLine())
                {
                    case"server":
                        Chat_Server.SimpleServer.Function();
                        Console.Title = "Server";
                        Console.ReadLine();
                        break;
                    case"client":
                        Chat_Server.Client.ClientConnect();
                        Console.Title = "Client";
                        Console.ReadLine();
                        break;
                }
    If I use this, I have to retype the cases 3 times (Until the third line) for it to take effect.. Here's an image for example.


    Here's the whole script
    Code:
    Console.ForegroundColor = ConsoleColor.Green; Console.Write("[MENU]");
                Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("What kind of user are you?\n\n\n \n 1-Type ''Server'' if you wish to start a server. \n 2- Type ''Client'' if you wish to connect to a server.");
                Console.ReadLine();
                Console.ReadLine().ToLower();
                switch (Console.ReadLine())
                {
                    case"server":
                        Chat_Server.SimpleServer.Function();
                        Console.Title = "Server";
                        Console.ReadLine();
                        break;
                    case"client":
                        Chat_Server.Client.ClientConnect();
                        Console.Title = "Client";
                        Console.ReadLine();
                        break;
                }
    Any ideas? :S

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Console string manipulating

    That's because you have Console.WriteLine 3 times in your code

    Code:
    Console.ForegroundColor = ConsoleColor.Green; Console.Write("[MENU]");
                Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("What kind of user are you?\n\n\n \n 1-Type ''Server'' if you wish to start a server. \n 2- Type ''Client'' if you wish to connect to a server.");
                string user_type = Console.ReadLine();
                switch (user_type.ToLower())
                {
                    case"server":
                        Chat_Server.SimpleServer.Function();
                        Console.Title = "Server";
                        Console.ReadLine();
                        break;
                    case"client":
                        Chat_Server.Client.ClientConnect();
                        Console.Title = "Client";
                        Console.ReadLine();
                        break;
                }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured