Thursday, August 12, 2010

Visual Basic String Statement : Mid

The Mid statement enables you replace the characters at an arbitrary location in a string.

Syntax :
Mid ( strResultString , ingStart [ , ingLength ] ) = strExpression
MidB ( strResultString , ingStart [ , ingLength ] ) = strExpression

strResultString : String in which you want to replace a substring with another substring.
ingStart : Starting position for the replacement
ingLength : Number of characters of the substring to be replaced
strExpression : Replacement value for the substring

Dim strHello as String
strHello = "Hello, Dolly"
Mid ( strHello , 1 , 5 ) = "Oh my"

Mid ( strHello , 8 ) = "Beck"

The first example replaces "Hello" in strHello with "Oh my". The second example starts at the eighth position and replaces whatever text is there with "Beck". Because the length is not specified , the replacement is effective for the length of "Beck". This makes strHello's final value "Oh my, Becky"

No comments:

Post a Comment