Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Visual Basic and Visual FoxPro functions to search strings
VBAInstr(), InstrRev() |
VFPAt(), AtC(), AtCC(), Rat(), Occurs() |
Visual Basic Syntax Notes
The VBA function Instr() returns the position of one string within another. This example will return 5 because "E" first occurs as the 5th character of "ABCDEFGHABCDEFGH":
If the target can't be found in the string then Instr() will return 0. The search is case-insensitive.
The InstrRev() function will search backwards from the end of the string. This example will return 13 because "E" last occurs as the 13th character of "ABCDEFGHABCDEFGH":
Visual FoxPro Syntax Notes
The simple functions At() returns the position of one string within another. This example will return 5 because "E" first occurs as the 5th character of "ABCDEFGHABCDEFGH":
If the target can't be found in the string then At() will return 0. The search is case-sensitive. Use the FoxPro AtC() function for a case-insensitive search.
The Rat() function will search backwards from the end of the string. This example will return 13 because "E" last occurs as the 13th character of "ABCDEFGHABCDEFGH":
Both the At() and Rat() functions can take a third numeric parameter to specify whether FoxPro should report the first, second or nth instance of the character. This example will return 13 because it is looking for the second occurence of the target and "E" makes its second appearance as the 13th character of "ABCDEFGHABCDEFGH":
The FoxPro Occurs() function counts the number of times that a character occurs in another string.
Warning
This area of the language is fraught with inconsistencies:
- The order of the parameters is reversed in the two languages.
- FoxPro is case-sensitive, Visual Basic isn't.
- Both languages have an optional third parameter. Visual Basic specifies that the search should start from the nth position; Visual FoxPro specifies that the search should return the nth occurrence.