Visual Basic and Visual FoxPro functions to manipulate characters




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:


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:


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:


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

Changing Case  |  Text functions  |  Repeating characters