KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: The Replace String command is not case sensitive
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: March 23, 2001

If you are using the Replace String command, and wish to replace the letter "x" with the letter "X" and your code looks something like:

$CAPITAL:="X"
$lower_case:="x"

$text:="This is x a small letter"

$text:=Replace String($text;$CAPITAL;"A") ` NOT what we want
$text:=Replace String($text;$lower_case;"A") ` what we want

This code will not work, because the Replace String command is NOT case sensitive. Therefore since the Replace String command is NOT a case sensitive, the only way to compare "x" to "X" is by comparing their ASCII values. Here is sample code that will solve the problem above.


$text:="this is the answer: X"
$replaceChar:="A"
$searchChar:="X"

For ($i;1;Length($text))
If (Ascii($text($i))=Ascii($searchChar))
$text($i):=$replaceChar
End if
End for

ALERT($text)

NOTE: In 4D, comparisons are not case sensitive.