October 26, 2016
Hot Topics:

String Functions Explained

  • November 19, 2002
  • By John Percival
  • Send Email »
  • More Articles »

Visual Basic provides several functions to format and retrieve parts of strings.

Joining strings with &

You can use the & operator to join two strings. This operation is called concatenation. For example:

FirstString = "This string has "
SecondString = "been concatenated!"
NewString = FirstString & SecondString

NewString would contain "This string has been concatenated!". Note that you need a space at the end of the first string or at the beginning of the second string, so that there is a space between "has" and "been".

Left$, Right$

These functions retrieve part of the string. The Left$ function returns characters from the left hand side, and the Right$ function returns characters from the right hand side. This is what they do:

MyString = "This is a nice long string"
LeftString = Left$(MyString, 7)
RightString = Right$(MyString, 6)

LeftString contains the text "This is", and RightString contains the text "string".


Left$(string, length)
Right$(string, length)


This function is used to retrieve part of a string, much like Left$ and Right$. This is how it is used:

MyString = "This is a nice long string"
NewString = Mid$(MyString, 6, 21)

NewString now contains "is a nice long string"


Mid(string, start[, length])

Page 1 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel