JavaScript Editor js editor     Web development 



Main Page

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])

Parameters

cSearched


Specifies the character expression to search. cSearched can be a memo field.
cExpressionSought


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.
Note:
If you need to specify only the nFlags setting along with the required parameters, specify –1 for the optional parameters you want disregarded.

The following table lists the values for nFlags:

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.

1

Search is case-insensitive and replacement is performed with exact cReplacement text.

2

Search is case-sensitive and replacement is performed with the case of cReplacement changed to match the case of the string found.

3

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.

Return Value

Character. STRTRAN(В ) returns the resulting character string.

Example

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".

В Copy Code
STORE 'abracadabra' TO gcString
? STRTRAN(gcString, 'a', 'z')  
? STRTRAN(gcString, 'a', 'q', 2, 3)  

See Also



JavaScript Editor js editor     Web development