xHarbour Reference Documentation > Function Reference |
Searches and replaces characters within a character string or memo field.
StrTran( <cString> , ; <cSubString>, ; [<cReplace>] , ; [<nStart>] , ; [<nCount>] ) --> cNewString
The function returns a copy of <String> where <cSubString> is replaced with <cReplace>.
StrTran() is a powerful search and replace function used to modify character strings. The function searches <cSubString> in the input string and replaces it with the replacement string. If <nStart> and <nCount> are not specified, all occurrances of <cSubString> are replaced. The search and replacement strings do not need to have the same length.
See also: | At(), HardCR(), HB_RegExReplace(), MemoTran(), RAt(), StrDel(), Stuff(), SubStr() |
Category: | Character functions |
Source: | rtl\strtran.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example shows various possibilities for StrTran() usage. // It begins with simple character search and replacements. At the // end, StrTran() is used to create a macro expression that creates // an array from a character string. PROCEDURE Main LOCAL cString := "a,BBB,cccc" LOCAL aArray ? StrTran( cString, "B" ) // result: a,,cccc ? StrTran( cString, "B", "b", 2 ) // result: a,Bbb,cccc ? StrTran( cString, "c", "C", 2 , 2 ) // result: a,BBB,cCCc aArray := &( '{"' + StrTran( cString, ',', '","' ) + '"}' ) ? aArray[1] // result: a ? aArray[2] // result: BBB ? aArray[3] // result: cccc RETURN
http://www.xHarbour.com