Click here to Skip to main content
12,351,441 members (34,462 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.6K views
3 bookmarked
Posted

How to Toggle String Case in .NET

, 14 Feb 2011 CPOL
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 is a full-stack software developer (Win/Web/Mobile). He holds PhD in EE/IT, published 300+ articles, authored 37 inventions and is credited for 10+ Enterprise level projects; currently focused on HTML5/CSS3, Javascript/jQuery, .NET/WPF/C#, Android/Angular.js, 'Big Data', AI, IoT. Alex participated in App Innovation Contests (AIC 2102/2013) with multiple winning submissions. Sample projects/pubs:
  1. Real-time NY Bus monitoring app (IoT)
  2. Semaphon™ semantic phone num-to-text converter
  3. Educational Web Portal
  4. Free Online NY Payroll Tax Calculator
  5. WebTV powered by Embedded YouTube Player (Goog #1 YouTube API for ASP.NET)
  6. Top-50 Digital Cameras (powered by iMark-DCAM rating engine)
  7. Pure CSS3 Slide Show
  8. Inflation Calculator
  9. CSS3 Modal Pop-up Dialog
  10. Multilingual Geocoder with Interactive Map
  11. Online Semantic Analyzer (Concordance Calculator)
  12. NY City Job Market and Agency Ratings
  13. Advanced CSS3 Table Formatting

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 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 14 Feb 2011
Article Copyright 2011 by DrABELL
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid