Click here to Skip to main content
11,647,659 members (69,901 online)
Click here to Skip to main content

Tagged as

How to Toggle String Case in .NET

, 14 Feb 2011 CPOL 2.8K 3
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. A. Bell has 20+ years of Software and Electrical Engineering experience: Win/Web veteran, published 300+ articles and authored 37 inventions, credited for 10+ Enterprise level projects (>250k code lines); currently focused on .NET/WPF/C#, Javascript/jQuery, 'Big Data', AI, IoT and Mobile apps. Participated in App Innovation Contest (AIC 2102/2013) with several winning submissions. Sample projects/pubs follow:
  1. WebTV Project: Embedded YouTube Player (Goog #1 YouTube API for ASP.NET)
  2. Edumatter M12: School Math Calculators and Equation Solvers (contest winner)
  3. Engineering Calculator VOLTA-2013 (contest winner)
  4. Online 3 Fractions Calculator (#1 on Goog)
  5. Engineering Calculator VOLTA-814 for Windows
  6. Real-time NY Bus monitoring app
  7. Inflation Calculator
  8. PaydayNY-2015 Payroll Tax Calculator (Win)
  9. Multilingual Geocoder with Interactive Map
  10. Semantic Analyzer (Concordance Calculator)
  11. Prime Factoring Calculator

You may also be interested in...

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    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 | Terms of Use | Mobile
Web03 | 2.8.150804.3 | Last Updated 14 Feb 2011
Article Copyright 2011 by DrABELL
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid