Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

How to Toggle String Case in .NET

, 24 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
What about this :) string ToggleStringCase(string strToToggle){ StringBuilder sb = new StringBuilder(); foreach(char ch in strToToggle.ToCharArray()) { if((int)ch>=65&&(int)ch<91) { sb.Append((char)((int)ch+32)); } else...
What about this Smile | :)
string ToggleStringCase(string strToToggle)
{
   StringBuilder sb = new StringBuilder();
   foreach(char ch in strToToggle.ToCharArray())
   {
      if((int)ch>=65&&(int)ch<91)
      {
        sb.Append((char)((int)ch+32));
      }
      else if((int)ch>=97&&(int)ch<123)
      {
        sb.Append((char)((int)ch-32))
      }
      else
      {
        sb.Append(ch);
      }
    }
   return sb.ToString();
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

code in play
Software Developer (Senior)
India India
4+ year experience in Microsoft technologies(C#.Net,ASP.Net, SQL server and Sharepoint).
Follow on   Twitter

Comments and Discussions

 
GeneralThis version is similar to the Alternate 1 posted by Robert ... PinmemberDrABELL25-Feb-11 13:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 24 Feb 2011
Article Copyright 2011 by code in play
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid