STRTRAN( ) Function

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, a blob field, or a varbinary expression.

cExpressionSought

Specifies the character expression to search for in cSearched. The search is case-sensitive. cExpressionSought can be a memo field, a blob field, or a varbinary expression.

cReplacement

Specifies the character expression to replace every occurrence of cExpressionSought in cSearched. Omitting cReplacement replaces every occurrence of cExpressionSought with an empty string. cReplacement can also be a memo field, a blob field, or a varbinary expression.

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.

NoteNote

If you need to specify only the nFlags setting along with the required parameters, specify empty string for the cReplacement and –1 for the optional numeric parameters you want disregarded.

nFlags

Specifies the case-sensitivity of a search according to the following values.

The following table lists the values for nFlags:

nFlags Description

0

Search is case-sensitive and replacement is performed with exact cReplacement text. (Default)

NoteNote

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.

NoteNote

The case of cReplacement changes only if the string found is all uppercase, lowercase, or proper case.

Expand imageReturn Value

Expand imageExample

Expand imageSee Also


© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic