Click here to Skip to main content
13,199,669 members (71,777 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.5K views
3 bookmarked
Posted 10 Feb 2011

How to Toggle String Case in .NET

, 14 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Test Page for both Algorithms: http://webinfocentral.com/resources/toggleCaseAlgorithm.aspx[^]Algorithm by Robert R.: protected string ToggleCaseByRobert(string s) { var sb = new StringBuilder(s.Length); foreach (char c in s) ...
Test Page for both Algorithms: http://webinfocentral.com/resources/toggleCaseAlgorithm.aspx[^]

Algorithm by Robert R.:

protected string ToggleCaseByRobert(string s)
{
    var sb = new StringBuilder(s.Length);
    foreach (char c in s)
        sb.Append(char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c));
    return sb.ToString();
}

Algorithm by John S.:
protected string ToggleCaseByJohn(string s)
{
    StringBuilder mystring = new StringBuilder(s);
    for (int i = 0; i < mystring.Length; i++) {
        char c = mystring[i];
        mystring[i] = Char.IsLower(c) ? Char.ToUpper(c) : Char.ToLower(c);
    }
    return mystring.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

DrABELL
President Infosoft International Inc
United States United States
Dr. Alexander Bell is a seasoned full-stack Software Engineer (Win/Web/Mobile). He holds PhD in EE/IT, authored 37 inventions and published 300+ technical articles. Currently focused on HTML5/CSS3, Javascript, .NET/WPF/C#, Angular.js, SQL, 'Big Data', Machine Learning, AI, IoT. Alex participated in App Innovation Contests (AIC 2102/2013) with multiple winning submissions. Portfolio samples:

  1. Real-time NY Bus Tracking Web App (IoT)
  2. Integrated Sensors Hub (IMU) Testing Web Page
  3. Semaphon™ semantic phone num-to-text converter
  4. Educational Web Portal
  5. Free Online NY Payroll Tax Calculator
  6. WebTV powered by YouTube Player powered by .NET API (#1 on Google)
  7. Top-50 Digital Cameras (by iMark-DCAM rating engine)
  8. Engineering Calculator VOLTA
  9. Big Data: Facebook and YouTube
  10. NY City Trivia Quiz
  11. NY Photo Gallery
  12. Publications by A. Bell

You may also be interested in...

Pro

Comments and Discussions

 
GeneralI have to question your testing methodology and conclusion a... Pin
Rod Kemp14-Feb-11 1:17
memberRod Kemp14-Feb-11 1:17 
GeneralThanks for your note; I have already noticed and corrected t... Pin
DrABELL10-Feb-11 8:52
memberDrABELL10-Feb-11 8:52 
GeneralFYI, the algorithm was posted by Robert Rohde. Deeksha just ... Pin
AspDotNetDev10-Feb-11 7:57
protectorAspDotNetDev10-Feb-11 7:57 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171020.1 | Last Updated 14 Feb 2011
Article Copyright 2011 by DrABELL
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid