| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Replaces characters if two substrings in two strings have the same position.
CharRelRep( <cSearch1>, ;
<cString1>, ;
<cSearch2>, ;
<cString2>, ;
<cReplace> ) --> cResult
The function searches <cSearch1> in <cString1>, and <cSearch2> in <cString2>. If both search strings are found at the same position in both strings, the function replaces characters in <cString2> until no more match is found. The return value <cString2> when no match is found at all.
| See also: | CharRela() |
| Category: | CT:String manipulation , Character functions |
| Source: | ct\relation.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example replaces digits with "X" based on the position of letters
// in a comparison string.
PROCEDURE Main
LOCAL cStr1 := "abbaacc"
LOCAL cStr2 := "0011011"
? CharRelRep( "a", cStr1, "1", cStr2, "X" ) // result: 001X011
? CharRelRep( "b", cStr1, "1", cStr2, "X" ) // result: 00X1011
? CharRelRep( "c", cStr1, "1", cStr2, "X" ) // result: 00110XX
? CharRelRep( "c", cStr1, "0", cStr2, "X" ) // result: 0011011
RETURN
http://www.xHarbour.com