私は既存のコードをゆっくりとDelphi2010に変換し、EmbarcaedroWebサイトのいくつかの記事とMarcoCantúホワイトペーパーを読んでいます。
私が理解していないことがまだいくつかあるので、ここに私の質問を例示するための2つの関数があります。
function RemoveSpace(InStr: string): string;
var
Ans : string;
I : Word;
L : Word;
TestChar: string[1];
begin
Ans := '';
L := Length(InStr);
if L > 0 then
begin
for I := 1 to L do
begin
TestChar := Copy(InStr, I, 1);
if TestChar <> ' ' then Ans := Ans + TestChar;
end;
end;
RemoveSpace := Ans;
end;
function ReplaceStr(const S, Srch, Replace: string): string;
var
I: Integer;
Source: string;
begin
Source := S;
Result := '';
repeat
I := Pos(Srch, Source);
if I > 0 then begin
Result := Result + Copy(Source, 1, I - 1) + Replace;
Source := Copy(Source, I + Length(Srch), MaxInt);
end
else Result := Result + Source;
until I <= 0;
end;
RemoveSpace関数の場合、Unicode文字が渡されなければ(たとえば、「aa bb」)、すべて問題ありません。ここで、テキスト「ab cd」を渡すと、関数は期待どおりに機能しません(出力としてab ?? cdを取得します)。
文字列で可能なUnicode文字をどのように説明できますか?Length(InStr)の使用は、Copy(InStr、I、1)と同様に明らかに正しくありません。
このコードをUnicode文字を考慮して変換する最良の方法は何ですか?
ありがとう!