Searches a character expression or memo field for a second character expression or memo field and replaces each occurrence with a third character expression or memo field. You can specify where the replacement begins and how many replacements are made.
STRTRAN(cSearched, cExpressionSought [, cReplacement] [, nStartOccurrence] [, nNumberOfOccurrences] [, nFlags])
- Specifies the character expression to search. cSearched can be a memo field.
- Specifies the character expression to search for in cSearched. The search is case-sensitive. cExpressionSought can be a memo field.
- [, cReplacement]
- Specifies the character expression to replace every occurrence of cSearchFor in cSearched. Omitting cReplacement replaces every occurrence of cExpressionSought with an empty string.
- [, nStartOccurrence]
- Specifies which occurrence of cExpressionSought to replace first. For example, if nStartOccurrence is 4, replacement begins with the fourth occurrence of cExpressionSought in cSearched and the first three occurrences of cExpressionSought remain unchanged. Omitting nStartOccurrence defaults the occurrence where replacement begins to the first occurrence of cExpressionSought.
- [, nNumberOfOccurrences]
- Specifies the number of occurrences of cExpressionSought to replace. Omitting nNumberOfOccurrences replaces all occurrences of cExpressionSought, starting with the occurrence specified with nStartOccurrence.
- [, nFlags]
Specifies the case-sensitivity of a search according to the following values.
The following table lists the values for nFlags:
Note: If you need to specify only the nFlags setting along with the required parameters, specify вЂ“1 for the optional parameters you want disregarded. nFlags Description
0 or -1
Search is case-sensitive and replacement is performed with exact cReplacement text. (Default)
Note: This setting specifies the original behavior for STRTRAN(В ) in versions prior to Visual FoxPro 7.0. You can also specify default behavior by passing вЂ“1 as the nFlags value.
Search is case-insensitive and replacement is performed with exact cReplacement text.
Search is case-sensitive and replacement is performed with the case of cReplacement changed to match the case of the string found.
Search is case-insensitive and replacement is performed with the case of cReplacement changed to match the case of the string found.
Note: The case of cReplacement changes only if the string found is all uppercase, lowercase, or proper case.
Character. STRTRAN(В ) returns the resulting character string.
The following example stores the string "abracadabra" to the variable gcString using the STORE command. The STRTRAN(В ) function replaces the character "a" with the character "z" and displays the string "zbrzczdzbrz" using the ? command. STRTRAN(В ) then replaces three occurrences of the character "a", beginning with the second occurrence, with the character "q" and displays "abrqcqdqbra".
STORE 'abracadabra' TO gcString ? STRTRAN(gcString, 'a', 'z') ? STRTRAN(gcString, 'a', 'q', 2, 3)