Click here to Skip to main content
13,349,539 members (51,011 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.2K views
2 bookmarked
Posted 14 Feb 2011

How to Toggle String Case in .NET

, 14 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Hi everybody-There is a question posted by Rod Kemp in regards to performance benchmarks used for both algorithms (see Alternate 4). The sample code snippet, pertinent to the "ToggleCaseByJohn" algorithm is as follows: DateTime dt = DateTime.Now; for (Int64 i = 0; i <...
Hi everybody-

There is a question posted by Rod Kemp in regards to performance benchmarks used for both algorithms (see Alternate 4). The sample code snippet, pertinent to the "ToggleCaseByJohn" algorithm is as follows:

DateTime dt = DateTime.Now;
for (Int64 i = 0; i < 100001; i++)
{
    TextBox2.Text = ToggleCaseByJohn(TextBox2.Text);
}
TimeSpan ts = DateTime.Now - dt;
double dur = (double)ts.Milliseconds / 100;
Label3.Text = dur.ToString() + " us";


This technique does not provide the "academic precision' of testing, but rather gives just a first order approximation with adequate accuracy pertinent to this task. Sure thing, more sophisticated benchmarks procedures could be constructed if necessary, but this one could do the job as specified (for example, instead of using the function call the body of the algorithm could be encapsulated within the code snippet shown above). Also, note that the number of iteration is selected as 100001: it should be odd number in order to see the string visually "toggled", because the even number will return the string to the original state.

Best regards,
Alexander Bell

PS. Link to the Test Page for both Algorithms:
http://webinfocentral.com/resources/toggleCaseAlgorithm.aspx[^]

PPS. On a separate note: suggested Alternate 7 is JUST WRONG because suggested "simplified" version:
char.IsUpper(c) ? char.ToLower(c) : c

is not the equivalent of original:
char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c)

As you can see, that "simplified" Alternate 7 version does not convert Lower Case into Upper; it only converts Upper-to-Lower.

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
Founder 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 Java/Javascript, .NET/C#, Android/Mobile, 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. Android Fraction Calculator "Fractal MK-12"
  3. Android Prime Factorization Calculator 18-digit)
  4. Semaphon™ semantic phone num-to-text converter
  5. Educational Web Portal
  6. Free Online NY Payroll Tax Calculator
  7. WebTV powered by YouTube Player powered by .NET API (#1 on Google)
  8. Engineering Calculator VOLTA
  9. Big Data: Facebook and YouTube
  10. NY City Trivia Quiz
  11. Publications by A. Bell

You may also be interested in...

Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 14 Feb 2011
Article Copyright 2011 by DrABELL
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid