Text cASES in Vb.NET
- Sentence Case (This is vb.net code)
Public Function SentenceCase(ByVal stringToConvert As String) As String Dim newStringBuilder As New StringBuilder newStringBuilder.Append(stringToConvert.ToLower) newStringBuilder.Chars(0) = newStringBuilder.Chars(0).ToString.ToUpper For letterCount As Integer = 0 To newStringBuilder.Length - 1 If newStringBuilder.Chars(letterCount) = "." Or newStringBuilder.Chars(letterCount) = "?" Or newStringBuilder.Chars(letterCount) = "!" Then If letterCount < newStringBuilder.Length - 1 Then If newStringBuilder.Chars(letterCount + 1) = " " Then newStringBuilder.Chars(letterCount + 2) = newStringBuilder.Chars(letterCount + 2).ToString.ToUpper Else newStringBuilder.Chars(letterCount + 1) = newStringBuilder.Chars(letterCount + 1).ToString.ToUpper End If End If End If Next Return newStringBuilder.ToString End Function
How To Use
Msgbox (SentenceCase("This Is Vb.Net Code"))
- Toggle Case (tHIS iS vB.nET cODE)
Public Shared Function Togglecase(ByVal origText As String) As String Dim counter As Integer Dim textParts() As String = Split(origText, " ") For counter = 0 To textParts.Length - 1 If (textParts(counter).Length > 0) Then _ textParts(counter) = _ LCase(Microsoft.VisualBasic.Left( _ textParts(counter), 1)) & _ UCase(Mid(textParts(counter), 2)) Next counter Return Join(textParts, " ") End Function
How To Use
Msgbox (Togglecase("This Is Vb.Net Code"))
- Capitalize Case (This Is Vb.Net Code)
Public Shared Function CapitalizeCase(ByVal origText As String) As String Dim counter As Integer Dim textParts() As String = Split(origText, " ") For counter = 0 To textParts.Length - 1 If (textParts(counter).Length > 0) Then _ textParts(counter) = _ UCase(Microsoft.VisualBasic.Left( _ textParts(counter), 1)) & _ LCase(Mid(textParts(counter), 2)) Next counter Return Join(textParts, " ") End Function
How To Use
Msgbox (Togglecase("this is vb.net code"))
- Lower Case (this is vb.net code)
How To Use
MsgBox("THIS IS VB.NET CODE".ToLower)
- Upper Case (THIS IS VB.NET CODE)
How To Use
MsgBox("this is vb.net code".ToUpper)