LOG IN

Forgot Your Password?


Incorrect login or password

SIGN UP



Existing user?

Forgot Password


Existing user?

String Operator

String Operator
String concatenation

The "&" operator joins two strings together. Example:

  Dim String1 As String = "123"
  Dim String2 As String = "456"
  Dim String3 As String
  String3 = String1 & String2 ' Results in "123456".

This will result in String3 being equal to "123456"

The "+" operator may be used in place of "&". However, it is not recommended.
Concat

You may concatenate a number of strings:

  Dim String1 As String = "Let"
  Dim String2 As String = " us"
  Dim String3 As String = " concatenate!"
  Dim strOutput As String
  strOutput = String.concat(String1,String2,String3) ' Results in "Let us concatenate!".

If you have defined a string array, such as:

  Dim strArr As String() = {"I", " am", " your", " automatic", " lover."}

then all the elements of this array may be concatenated in a simple way:

  strOutput = string.concat(strArr) ' Results in "I am your automatic lover."

String manipulations functions

    Lcase(): converts in higher case.
    Ucase(): converts in lower case.

To create some substrings, the VB6 functions are still available:

    Left(): left part.
    Right(): right part.
    Mid(): middle part.
    InStr(): substring location into a string.
    Replace(): replace a substring by another one.

    Sub Main()
        Dim StringName As String = "lorem ipsum dolor sit amet"
        StringName = StringName.Replace("i", "o")
        Console.WriteLine(Mid(StringName, InStr(StringName, " "), 6))
        Console.ReadLine()  ' Displays " opsum"
    End Sub

Source: https://en.wikibooks.org/wiki/Visual_Basic_.NET/String_and_character_operators


 << Previous  Next >>