STRTRAN( ) Function

Searches a character expression or memo field for occurrences of a second character expression or memo field, and then replaces each occurrence with a third character expression or memo field.

STRTRAN(cSearched, cExpressionSought [, cReplacement]
   [, nStartOccurrence] [, nNumberOfOccurrences] [, nFlags])

Return Values



  • cSearched
    Specifies the character expression that is searched. cSearched can be a memo field.

  • cExpressionSought
    Specifies the character expression that is searched for in cSearched. The search is case-sensitive. cExpressionSought can be a memo field.

  • cReplacement
    Specifies the character expression that replaces every occurrence of cSearchFor in cSearched. If you omit cReplacement, every occurrence of cExpressionSought is replaced with the empty string.

  • nStartOccurrence
    Specifies which occurrence of cExpressionSought is the first to be replaced. 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. The occurrence where replacement begins defaults to the first occurrence of cExpressionSought if you omit nStartOccurrence.

  • nNumberOfOccurrences
    Specifies the number of occurrences of cExpressionSought to replace. If you omit nNumberOfOccurrences, all occurrences of cExpressionSought, starting with the occurrence specified with nStartOccurrence, are replaced.

  • nFlags
    Specifies the case-sensitivity of a search according to the following values:

    nFlags Value Description
    0 (default) Search is case-sensitive, replace is with exact cReplacement text. This is the behavior in the previous version of Visual FoxPro.
    1 Search is case-insensitive, replace is with exact cReplacement text.
    2 Search is case-sensitive, replace is with exact cReplacement text.
    3 Search is case-insensitive; case of cReplacement is changed to match the case of cExpressionSought, which it replaces.

    You can also specify default behavior by passing –1 as the nFlags value.


You can specify where the replacement begins and how many replacements are made. STRTRAN( ) returns the resulting character string. Specify –1 for optional parameters you want to skip over if you just need to specify the nFlags setting.


STORE 'abracadabra' TO gcString
? STRTRAN(gcString, 'a', 'z')  && Displays zbrzczdzbrz
? STRTRAN(gcString, 'a', 'q', 2, 3)  && Displays abrqcqdqbra

See Also

CHRTRAN( ) | CHRTRANC( ) | STUFF( ) | Creating Character Expressions | STUFFC( ) Function