Tips

Replace Stringコマンドは大文字小文字を区別しません

日付2001/03/23
ID01-546
バージョンall versions
プラットフォームWindows and Mac

Replace Stringコマンドを使用して、文字列「x」を「X」に置き換えたい場合に、以下のようなコードにしてみます:

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

このコードではうまく機能しません。それは、Replace Stringコマンドが大文字小文字を区別しないからです。
従って、Replace Stringコマンドが大文字小文字を区別しないので、「x」を(と)「X」と比較する唯一の方法は、それらのASCIIコードを使って比較します。
以下は、上記問題を解決するためのサンプルコードです。

$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)

注意: 4Dでの文字列の比較は、大文字小文字の区別をしません。