Click here to Skip to main content
12,699,531 members (33,591 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.1K views
3 bookmarked
Posted

How to Toggle String Case in .Net

, 11 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Interesting finding in regards to the Case Toggle Algorithm by Robert (see the following code snippet): protected string ToggleCaseByRobert(string s){ var sb = new StringBuilder(s.Length); foreach (char c in s) sb.Append(char.IsUpper(c) ? char.ToLower(c) :...
Interesting finding in regards to the Case Toggle Algorithm by Robert (see the following code snippet):
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();
}


The functionality will stay the same if the line:
var sb = new StringBuilder(s.Length);

is replaced with simplified version:
var sb = new StringBuilder();

but the original version demonstrates about 5...10% performance boost. Kudos to Robert Rohde for this useful tip!

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. Pure CSS3 Slide Show

  9. Inflation Calculator

  10. Multilingual Geocoder with Interactive Map

  11. Online Semantic Analyzer (Concordance Calculator)

  12. Advanced CSS3 Table Formatting


You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 11 Feb 2011
Article Copyright 2011 by DrABELL
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid