String Functions In VB

String functions are mainly used to manipulate the string in Visual basic.

GetChar

Gets the character from the string of particular index number.
  1. GetChar("This is a string", 7)  
Above code snippet will return "s".

InStr

Returns the starting position in a string of a substring, counting from 1.
  1. InStr("This is a string""string")  
Above code snippet will returns 11.

InStrRev

Returns the starting position in a string of a substring, searching from the end of the string.
  1. InStrRev("This is a string""string")  
Above code snippet will returns 6.

LCase

Returns the lower-case conversion of a string.
  1. LCase("THIS IS A STRING")  
Above code snippet returns "this is a string".

Left

Returns the left-most specified number of characters of a string.
  1. Left("This is a string", 4)  
Above code snippet returns "This".

Len

Returns the length of a string.
  1. Len("This is a string")  
Above code snippet returns 16.

LTrim

Removes any leading spaces from a string.
  1. LTrim(" This is a string")  
Above code snippet returns "This is a string".

Mid

Returns a substring from a string, specified as the starting position (counting from 1) and the number of characters.
  1. Mid("This is a string", 6, 4)  
Above code snippet returns "is a".

Replace

Replaces all occurences of a substring in a string.
  1. Replace("This is a string"" s"" longer s")  
Above code snippet returns "This are a longer string" (replaces an "s" preceded by a blank space).

Right

Returns the right-most specified number of characters of a string.
  1. Right("This is a string", 6)  
Above code snippet returns "string".

RTrim

Removes any trailing spaces from a string.
  1. RTrim("This is a string ")  
Above code snippet returns "This is a string".

Str

Returns the string equivalent of a number.
  1. Str(100)  
Above code snippet returns "100".

Space

Fills a string with a given number of spaces.
  1. "This" & Space(5) & "string"  
Above code snippet returns "This string".

StrComp

Compares two strings. Return values are 0 (strings are equal), 1 (first string has the greater value), or -1 (second string has the greater value) based on sorting sequence.
  1. StrComp("This is a string""This string")  
Above code snippet returns -1.

StrReverse

Reverses the characters in a string.
  1. StrReverse("This is a string")  
Above Code snippet returns "gnirts a si sihT".

Trim

Removes any leading and trailing spaces from a string.
  1. Trim(" This is a string ")  
Above returns "This is a string".

UCase

Returns the upper-case conversion of a string.
  1. UCase("This is a string")  
Above code snippet returns "THIS IS A STRING".

Val

Converts a numeric expression to a number.
  1. Val( (1 + 2 + 3)^2 )  
above code snippet returns 36.