Function StrTran() Foundation
Replaces characters in a character string or memo field.
StrTran( <cString>, <cSeek>, ;
[<cReplace>], [<nStart>], [<nCount>] ) --> cNewString
The return value of StrTran() is a character string in which <cSeek> is replaced with <cReplace> from the position <nStart> exactly <nCount> times.
The character function StrTran() searches a character string for a character or a string and replaces occurrences of this string with another character or string. When values are not specified for <nStart> and <nCount>, all instances of <cSeek> found are replaced with <cReplace>. When <cReplace> is not specified, <cSeek> is replaced with a null string (""), causing <cSeek> to be deleted from <cString>.
StrTran() replaces all occurrences of <cSeek>. To replace only a single occurrence of <cSeek>, the function Stuff() is used. For memo fields or character strings with control characters, the functions HardCR() and MemoTran() are used to replace carriage returns.
// The example shows various results of the function StrTran()
PROCEDURE Main
? StrTran("Abc;Abc;Abc", "Abc" )
// result: ;;
? StrTran("Abc;Abc;Abc", "Abc", "Def" )
// result: Def;Def;Def
? StrTran("Abc;Abc;Abc", "Abc", "Def", 2 )
// result: Abc;Def;Def
? StrTran("Abc;Abc;Abc", "Abc", "Def", 1, 1 )
// result: Def;Abc;Abc
RETURN
// In this example, StrTran() and the macro operator
// are used to convert the return value of SetColor()
// to an array which contains an individual color
// value with foreground and background color
// in each of its elements.
PROCEDURE Main
LOCAL aColor := ColorToArray( SetColor() )
AEval( aColor, {|cColor| QOut( cColor ) } )
RETURN
FUNCTION ColorToArray( cColor )
cColor := '{"' + StrTran( cColor, ',' , '","' ) + '"}'
RETURN &(cColor)
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.