String Manipulating Functions

 

 

1. The  Len Function

 The length function returns an integer value which is the length of a phrase or a sentence, including the empty spaces. The format is

Len (^Phrase ̄)

 

2 The Right  Function

The Right function extracts the right portion of a phrase. The format is

Right (^Phrase ̄, n)

Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted. 

 

3 The Left Function

The Left$ function extract the left portion of a phrase. The format is

Left(^Phrase ̄, n)

Where n is the starting position from the left of the phase where the portion of the phrase is going to be extracted. 

 

 4 The Ltrim Function

The Ltrim function trims the empty spaces of the left portion of the phrase. The format is

Ltrim(^Phrase ̄)

 

5 The Rtrim Function

The Rtrim function trims the empty spaces of the right portion of the phrase. The format is

Rtrim(^Phrase ̄)

.

6    The Trim function

The Ttrim function trims the empty spaces on both side of the phrase. The format is

Trim(^Phrase ̄)

.

7 The Mid Function

 The Mid function extracts a substring from the original phrase or string. It takes the following format:

Mid(phrase, position, n)

Where position is the starting position of the phrase from which the extraction process will start and n is the number of characters to be extracted.

 

8 The InStr function

 The InStr function looks for a phrase that is embedded within the original phrase and returns the starting position of the embedded phrase. The format is

Instr (n, original phase, embedded phrase)

Where n is the position where the Instr function will begin to look for the embedded phrase. For example

 

 

Example 14.1

This is a program that utilizes some of the functions mentioned in this lesson.

The output is shown in figure on the right.

 Private Sub Form_Activate()

Print Len("Visual Basic")

Print Right("Visual Basic", 4)

Print Left("Visual Basic", 4)

Print LTrim("   Visual Basic")

Print LTrim("Visual Basic     ")

Print Trim("   Visual Basic   ")

Print InStr(5, "  Visual  ", " ")

Print InStr(6, Trim$("   Visual Basic   "), " ")

Print Mid("Visual Basic", 3, 6)

Print InStr(1, "Visual Basic", "Basic")

End Sub

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[Back to VBToday]