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,943 questions

51,884 answers

573 users

How to uppercase (capitalize) the first letter (character) of a string in VB.NET

3 Answers

0 votes
Module Module1

    Sub Main()

        Dim s1 As String = "obi-wan kenobi"
        Dim s2 As String = "vb programming language"

        s1 = UppercaseFirstCharacter(s1)
        Console.WriteLine(s1)

        s2 = UppercaseFirstCharacter(s2)
        Console.WriteLine(s2)

    End Sub

    Function UppercaseFirstCharacter(s As String) As String

        If (s.Length > 0) Then

            Dim arr() As Char = s.ToCharArray()

            arr(0) = Char.ToUpper(arr(0))

            Return New String(arr)

        End If

        Return s

    End Function

End Module

' run:
' 
' Obi-wan kenobi
' Vb programming language

 



answered Jan 24, 2017 by avibootz
edited Jan 24, 2017 by avibootz
0 votes
Imports System.Runtime.CompilerServices

Module Module1

    Sub Main()

        Dim s1 As String = "obi-wan kenobi"
        Dim s2 As String = "vb programming language"

        s1 = s1.UppercaseFirstCharacter()
        Console.WriteLine(s1)

        s2 = s2.UppercaseFirstCharacter()
        Console.WriteLine(s2)

    End Sub

    ' Extension Method
    <Extension()>
    Function UppercaseFirstCharacter(s As String) As String

        If (s.Length > 0) Then

            Dim arr() As Char = s.ToCharArray()

            arr(0) = Char.ToUpper(arr(0))

            Return New String(arr)

        End If

        Return s

    End Function

End Module

' run:
' 
' Obi-wan kenobi
' Vb programming language

 



answered Jan 24, 2017 by avibootz
edited Jan 24, 2017 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim s1 As String = "vb is a programming language"
        Dim s2 As String = "star wars is an American epic space film series"

        s1 = UppercaseFirstCharacter(s1)
        s2 = UppercaseFirstCharacter(s2)

        Console.WriteLine(s1)
        Console.WriteLine(s2)

    End Sub

    Function UppercaseFirstCharacter(s As String) As String

        If (String.IsNullOrEmpty(s)) Then
            Throw New ArgumentException("String Is Null Or Empty")
        End If

        Return s.First().ToString().ToUpper() + s.Substring(1)

    End Function

End Module

' run:
' 
' Vb is a programming language
' Star wars Is an American epic space film series





 



answered Jan 24, 2017 by avibootz
...