Xbasic

CHRTRAN Function

Syntax

Output_String as C = CHRTRAN(C string_1,C string_2,C string_3)

Arguments

string_1

Input String. A character string to translate.

string_2

Search Pattern. A character string as the same length as input string containing characters likely and unlikely to match Input_String.

string_3

Replace Pattern. A character string as the same length as Input_String containing the characters to substitute when a character in Search_Pattern matches a character in Input_String.

Description

Replaces a portion of one string with another.

Discussion

CHRTRAN() returns a character string where characters in string_1 that match those in string_2 have been replaced with characters in the same position in string_3. Case sensitive. Common uses include changing character values within either a global update or an append operation. CHRTRAN() is especially useful for blanking specific positions in fields and for changing formatting characters used within a character code.

Example

chrtran( "(617)229-2924" , "(XXX)XXX-XXXX" , " XXX XXX-XXXX" ) -> " 617 229-2924"
chrtran( "AaBbCcDd" , "XXBXXXXX" , "XXbXXXXX" ) -> "AabbCcDd"

Assume the HOMEPHONE field contains values such as "(102)345-6789" and "(304)567-8901". In the following expression, since only the parentheses specified in string_2 match any values in HOMEPHONE, CHRTRAN() forms values using all the other characters from a HOMEPHONE value, plus the spaces included in the first and fifth position from string_3.

chrtran(HOMEPHONE, "(AAA)AAA-AAAA", " AAA AAA-AAAA")

For the records containing the values listed above, CHRTRAN() returns " 102 345-6789" and " 304 567-8901".

See Also