Visual Basic and Visual FoxPro substrings

VBA

Left(), Right(), Mid();

VFP

Left(), Right(), SubStr(), StrExtract()

Common Syntax Notes

The Left() and Right() functions are the same in both languages. Both take a string and a number as parameters and both will return the leftmost or rightmost n characters of that string. The expression:

Left("Hello Mum", 5)

will return the first five characters of the first parameter passed into the function and will give you the string "Hello".

Note that both languages are 1-based. The first character of the string is character number 1, not zero. In VBA you can use Option Base 0 to force array elements to begin numbering at zero but this option does not affect the way that characters are numbered within a string.

Visual Basic Syntax Notes

VBA uses Mid() to return characters from the middle of the string.

All the VBA string processing functions exist in two forms, one of which has a "$" suffix to indicate that the function will return a string. As an example, the Left() function returns the leftmost characters as a variant data type whereas the Left$() functions returns them as a string.

Visual FoxPro Syntax Notes

VFP uses the SubStr() function to read characters from the middle of a string and also has the StrExtract() function to return the characters between two specified delimiters in a string.

FoxPro has always been a weakly-typed language so there is no need for the distinction between variant (all Fox variables are variant) and string functions. Visual FoxPro does have a set of text-handling functions with a "C" suffix which handle strings in double-byte character sets, for example LeftC().

Concatenation  |  Text functions  |  Trimming spaces

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

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

Finding characters in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to find the position of one character inside another string.

Read More