Finding characters in a VBA or VFP string

VBA

Instr(), InstrRev()

VFP

At(), AtC(), AtCC(), Rat(), Occurs()

Notes

The simple functions Instr() and At() return the position of one string within another. Be aware that the order of the parameters is reversed in the two languages. Both these examples will return the value 5.

pos = Instr("ABCDEFGH", "E")   '  VBA
pos = At("E", "ABCDEFGH")      && VFP

Both languages will return 0 if the target can't be found. In VBA the search is case-insensitve, in VFP the search is case-sensitive. Use the AtC() function in VFP for a case-insensitive search.

Both languages have related commands which will search backwards from the end of the string or pick up a particular instance of the target. Again there is a source of confusion in the syntax. VBA lets you start from the nth character in the string being searched, VFP lets you find the nth occurrence of the target.

VFP's Occurs() function counts the number of times that a character occurs in another string.

Trimming spaces  |  Text functions  |  Changing Case

Access Tips

FoxPro Tips

General Tips

 

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 FoxPro and Visual Basic for Applications both use quotes to delimit strings but FoxPro has alternative methods.

Read More

Text concatenation in VBA and VFP

Concatenating text strings in Visual FoxPro and Visual Basic for Applications.

Read More

Text substrings in VBA and VFP

Both Visual FoxPro and Visual Basic for Applications let you extract substrings from within a string of text

Read More

Trimming text in VBA and VFP

Both Visual FoxPro and Visual Basic for Applications let you trim leading and trailing spaces from string of text

Read More