Results 1 to 7 of 7

Thread: Switch case-sensitive

  1. #1

    Thread Starter
    Lively Member safewithyou247's Avatar
    Join Date
    Dec 2005
    Posts
    64

    Switch case-sensitive

    I have this portion of code in C#.

    VB Code:
    1. switch (stripCritical)
    2.             {
    3.                 case "Not critical": ratingNumber = 1; break;
    4.                 case "Less critical": ratingNumber = 2; break;
    5.                 case "Moderately critical": ratingNumber = 3; break;
    6.                 case "Highly critical": ratingNumber = 4; break;
    7.                 case "Extremely critical": ratingNumber = 5; break;
    8.             }

    The problem is that if something comes accross as "Not Critical" then it doesnt match. How can I make this switch statement ignore case?

    Thanks in advance.
    "A candle loses nothing by lighting another candle."

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Switch case-sensitive

    Code:
    switch (stripCritical.toLower())
    {
      case "not critical":
    Etc.

  3. #3

    Thread Starter
    Lively Member safewithyou247's Avatar
    Join Date
    Dec 2005
    Posts
    64

    Re: Switch case-sensitive

    I should have thought of that.

    Thank you very much.

    Also do you know of a good web page that tells how to put a file browser on my form?

    Thank you.
    "A candle loses nothing by lighting another candle."

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Switch case-sensitive

    In, or a Common Dialog?

  5. #5

    Thread Starter
    Lively Member safewithyou247's Avatar
    Join Date
    Dec 2005
    Posts
    64

    Re: Switch case-sensitive

    Common dialog.

    I have never made a file browser with code before and I would like to try on out and see how hard or easy it is.
    "A candle loses nothing by lighting another candle."

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Switch case-sensitive

    Code:
    OpenFileDialog ofd = new OpenFileDialog();
    if(ofd.ShowDialog() != DialogResult.Cancel)
    {
    MessageBox.Show(ofd.FileName);
    }
    Something like that?

  7. #7

    Thread Starter
    Lively Member safewithyou247's Avatar
    Join Date
    Dec 2005
    Posts
    64

    Re: Switch case-sensitive

    Wow!

    That was incredably easy.
    "A candle loses nothing by lighting another candle."

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