char.toLower()

This is a discussion on char.toLower() within the C# Programming forums, part of the General Programming Boards category; Code: int i; char c; while(true) { i = Console.Read(); if (i!=1) { c = (char) i; switch(c) { } ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    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 10:25 PM.
    Mr. C: Author and Instructor

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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 11:04 PM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21