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

Tagged as

Go to top

How to Toggle String Case in .NET

, 7 Dec 2011
Rate this:
Please Sign up or sign in to vote.
For VB.NET users:Public Function ToggleCase(input As String) As String Dim result As String = String.Empty Dim inputArray As Char() = input.ToCharArray() For Each c As Char In inputArray If Char.IsLower(c) Then result += [Char].ToUpper(c) Else result +=...

For VB.NET users:

Public Function ToggleCase(input As String) As String
	Dim result As String = String.Empty
	Dim inputArray As Char() = input.ToCharArray()
	For Each c As Char In inputArray
		If Char.IsLower(c) Then
			result += [Char].ToUpper(c)
		Else
			result += [Char].ToLower(c)
		End If
	Next
	Return result
End Function

One more:

Dim mystring As New StringBuilder("AbCd")
For i As Integer = 0 To mystring.Length - 1
    Dim c As Char = mystring(i)
    mystring(i) = If([Char].IsLower(c), [Char].ToUpper(c), [Char].ToLower(c))
Next

License

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

Share

About the Author

Jαved
Student
India India
« I Love to Code ».
In the meantime I like to surf the Internet and get to know about new Technology, Watching Movies and playing cricket.
 
Currently I'm doing Masters In Computers.

CodeProject helped me a lot to learn and I am always thankful to all the Members who make this happen.
Follow on   Twitter

Comments and Discussions

 
GeneralPosting a vb.net version of the same code is NOT an alternat... PinmvpJohn Simmons / outlaw programmer7-Dec-11 1:17 
Posting a vb.net version of the same code is NOT an alternative to the code in the original tip.

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
Web04 | 2.8.140916.1 | Last Updated 7 Dec 2011
Article Copyright 2011 by Jαved
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid