·  VB .NET - Syntax - Variables - String

 

- Info:

  - This tutorial shows how to create String and convert it to other Data Types.

 

- Procedure:

  - Create VB .NET Console Application Test.vb

 

    Test.vb

    Module Module1

    

      Sub Main()

    

        'CREATE.------------------------------------------------------------

        Dim text As String

            text   = "123453"

    

        'ANALYZE.-----------------------------------------------------------

        Dim index  As Long              'Index starts with 1.

        Dim length As Long

            index  = InStr(   text, "3")'3   First occurence of 3. 0 if 3 was not found.

            index  = InStr(4, text, "3")'6   First occurence of 3 after including 3rd character.

            length = Len(text)          '6   Returns number of characters in string.

    

        'MODIFY.------------------------------------------------------------

            text   = "012345  \n"

        Dim changed As String

            changed = replace  (text,"23","AB")    'Replace ALL occurrences of regex    "23" with "AB".

    

        'GET SUBSTRINGS.----------------------------------------------------

        Dim substr As String

            substr = Left (text, 2)     '12  Take 2 characters from the left.

            substr = Right(text, 2)     '45  Take 2 characters from the right.   

            substr = Mid  (text, 2 , 3) '234 Take 3 characters starting from 2nd one.

    

        'CONNECT.-----------------------------------------------------------

        Dim newString As String

            newString = text & " world"

            newString = text + " world"

    

        'DISPLAY.-----------------------------------------------------------

        MsgBox(index)

     

      End Sub

    

    End Module