Visual Basic and Visual FoxPro functions to manipulate characters

VBA

Mid()

VFP

Stuff(), ChrTran(), StrTran()

Visual Basic Syntax Notes

In VBA you can use the Mid() function to extract one or more characters from inside another string or to change those characters.

Visual FoxPro Syntax Notes

VFP has three functions to do a similar job.

The Stuff() function stuffs characters into a string. You can specify where the new characters should be put and how many of the original characters are to be replaced. As an example:

Stuff("ABCDEFGHABCDEFGH", 3, 0, "XXX")

will produce the string "ABXXXCDEFGHABCDEFGH". The function has inserted the new characters "XXX" into the original string at position 3 and has replaced none of the existing characters.

The StrTran() function performs a string translation. It replaces each occurrence of one character or string inside a string with another character or string. The expression:

StrTran("ABCDEFGHABCDEFGH", "D", "XXX")

will replace every occurrence of the string "D" with the string "XXX" and produce ABCXXXEFGHABCXXXEFGH.

The ChrTran() function is similar. It replaces each occurrence of one character inside a string with the matching character from another string. The expression:

ChrTran("ABCDEFGHABCDEFGH", "AE", "ae")

will replace every "A" with "a" and every every "E" with "e".

Changing Case  |  Text functions  |  Repeating characters

Related Items

VFP and VBA.

The Visual FoxPro and Visual Basic for Applications languages are similar but there are annoying differences between them.

Read More

Text delimiters in VBA and VFP.

Visual Basic for Applications and Visual FoxPro delimiters for strings.

Read More

Text concatenation in VBA and VFP

Visual Basic for Applications and Visual FoxPro operators to concatenate text.

Read More

Text substrings in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to extract substrings from within a string of text

Read More

Trimming text in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to trim leading and trailing spaces from string of text

Read More