A=STRTRAN('KHALID','ALI','123 ') MESSAGEBOX(A)Two solutions:
A=STRTRAN(STRTRAN('KHALID', SPACE(1) + 'ALI','123 '), 'ALI' + SPACE(1), '123) MESSAGEBOX(A)(2) (should always work), though you'll have to manually handle punctuation and unusual spacing:
FUNCTION substituteWord LPARAMETERS tcText, tcWordToSeek, tcWordNew, tlWholeWordOnly IF tlWholeWordOnly * Doing a word at a time * Note: If you are having punctuation or variable spacing, you'll have to handle that manually. lcResult = SPACE(0) FOR lnI = 1 to GETWORDCOUNT(tcText) lcWord = GETWORDNUM(tcText, lnI) IF lcWord == tcWordToSeek lcWord = STRTRAN(GETWORDNUM(tcText, lnI), tcWordToSeek, tcWordNew) ENDIF lcResult = lcResult + IIF(EMPTY(lcResult), SPACE(0), SPACE(1)) + lcWord NEXT * When we get here, every word was replaced RETURN lcResult ELSE * Doing any occurrence within RETURN STRTRAN(tcText, tcWordToSeek, tcWordNew) ENDIFUsage:
? substituteWord("kalid ali kha", "ali", "123", .f.) && Substitute NOT whole words ? substituteWord("kalid ali kha", "ali", "123", .t.) && Substitute ONLY whole words