Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

How to Toggle String Case in .NET

, 14 Feb 2011
Rate this:
Please Sign up or sign in to vote.
What about this?string s = new string(( from c in "ABCdef" select char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c) ).ToArray());Note by Alexander Bell: In regards to the performance, this one (i.e. Alternate 9) is the worst in comparison...
What about this?
 
string s = new string((
            from c in "ABCdef" 
            select char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c) 
           ).ToArray());
 
Note by Alexander Bell: In regards to the performance, this one (i.e. Alternate 9) is the worst in comparison with Alternate 1 and Alternate 2, also it requires Linq Library, which negatively impacts the Algorithm portability: Alternate 9 is NOT RECOMMENDED

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

TimB99
Software Developer
New Zealand New Zealand
No Biography provided

Comments and Discussions

 
GeneralThis one is actually Alternate 8 PinmemberDrABELL16-Feb-11 6:28 
This one is actually Alternate 8

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 | Mobile
Web03 | 2.8.140721.1 | Last Updated 14 Feb 2011
Article Copyright 2011 by TimB99
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid