Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,932 questions

51,869 answers

573 users

How to invert the letters case in a String uppercase to lowercase and lowercase to uppercase in VB.NET

3 Answers

0 votes
Imports System.Text

Module Module1

    Sub Main()

        Dim s As String = "VB.net Programming"

        s = InvertLettersCase(s)
        Console.WriteLine(s)

        Console.WriteLine(InvertLettersCase("Programming"))

    End Sub


    Public Function InvertLettersCase(s As String) As String

        Dim sb As New StringBuilder()

        For Each ch As Char In s
            If Char.IsLower(ch) Then
                sb.Append(Char.ToUpper(ch))
            ElseIf Char.IsUpper(ch) Then
                sb.Append(Char.ToLower(ch))
            Else
                sb.Append(ch)
            End If
        Next

        Return sb.ToString()

    End Function

End Module

' run:
' 
' vb.NET pROGRAMMING
' pROGRAMMING



answered Dec 8, 2016 by avibootz
edited Dec 8, 2016 by avibootz
0 votes
Imports System.Text

Module Module1

    Sub Main()

        Dim s As String = "VB.net Programming"

        s = InvertLettersCase(s)
        Console.WriteLine(s)

        Console.WriteLine(InvertLettersCase("Programming"))

    End Sub

    Public Function InvertCharCase(ch As Char) As Char
        If Char.IsLower(ch) Then Return Char.ToUpper(ch)
        If Char.IsUpper(ch) Then Return Char.ToLower(ch)
        Return ch
    End Function


    Public Function InvertLettersCase(s As String) As String

        Dim sb As New StringBuilder()

        For Each ch As Char In s
            sb.Append(InvertCharCase(ch))
        Next

        Return sb.ToString()

    End Function

End Module

' run:
' 
' vb.NET pROGRAMMING
' pROGRAMMING

 



answered Dec 8, 2016 by avibootz
edited Dec 8, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim s As String = "VB.net Programming"

        s = InvertLettersCase(s)
        Console.WriteLine(s)

        Console.WriteLine(InvertLettersCase("Programming"))

    End Sub

    Public Function InvertLettersCase(s As String) As String

        Dim rv

        rv = New String(s.Select(Function(c)
                                     Return If(Char.IsLower(c), Char.ToUpper(c), Char.ToLower(c))
                                 End Function).ToArray())
        Return rv

    End Function

End Module

' run:
' 
' vb.NET pROGRAMMING
' pROGRAMMING

 



answered Dec 8, 2016 by avibootz
edited Dec 8, 2016 by avibootz
...