Thread: char.toLower()

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    char.toLower()

    Code:
    int i;
    char c;
    while(true)
    {
    	i = Console.Read();
    	if (i!=1)
    	{
    		c = (char) i;
    		switch(c)
    		{
    		}
    	}
    }
    Obviously inside the switch statement I'm going to have case statements like
    Code:
    case 'z': // do something; break;
    but then there's the easily solved problem of case sensitivity. I have two options:

    1) Is there a char equivalent of String.toLower()

    2) It's been a while since I did this and my book does not explicitly clarify. In the following code, would my_function() execute regardless of the case of z/Z:

    Code:
    case 'z': case 'Z': my_function; break;
    Thanks.

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Sean,

    1. There is a Char.ToUpper() method. There is also String.ToLower/ToUpper as well.

    I would say

    ...

    Code:
    string s;
    char c;
    
    Console.WriteLine("Enter a character');
    s = Console.ReadLine();
    c =s[0] ;          //extract the 0 char from string
    
    switch (c)
    {
       case 'z':
       case 'Z':
       Console.WriteLine("Or do something");
       break;
       ...
    
    }
    Remember, about switch in C#

    1.C# accepts strings enums as well as integers.

    2. C# does not permit fall through. Break statements are required in C# unless two cases are combined with no statements between them (like above).

    Also, what C# book are you using?? Since I have a C# project going on right now.

    Mr. C.
    Last edited by Mister C; 07-08-2004 at 09:25 PM.
    Mr. C: Author and Instructor

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well actually I don't have a C# book. For syntax issues like this where it's likely to be very similar between the two languages, I refer to the User's Guide that came with my Borland Turbo C++ 3.0 for DOS compiler, and that is what I was talking about it. I don't even know where I learned C#. But thanks for the help!

    edit: I'll be using chars, not strings, if anyones cares. I needed to program to execute the desired option after the user presses just one key.
    Last edited by sean; 07-08-2004 at 10:04 PM.

Popular pages Recent additions subscribe to a feed