Text cASES in Vb.NET

  1. 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"))
  2. 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"))
  3. 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"))
  4. Lower Case (this is vb.net code)

    How To Use

    MsgBox("THIS IS VB.NET CODE".ToLower)
  5. Upper Case (THIS IS VB.NET CODE)

    How To Use

    MsgBox("this is vb.net code".ToUpper)

Recommended Answers

All 3 Replies

Not even 1 replay

Reply to what? All you did was post up some code without a question...

commented: Absolutley no reason for this down vote. Some doom puff wanting to make them selves feel better. +8

i meant a thanks replay
to encourage me
but never mind

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.