我想在 Delphi 中创建一个函数来计算两个字符串的不同级别。如果两个字符串相等(忽略大小写),那么它应该返回 0,但如果它们不相等,它应该返回不同字符的数量。此功能对于检查拼写非常有用。
function GetDiffStringLevel(S1,S2:string):Integer;
begin
if SameText(S1,S2) then Exit(0);
// i want get different chars count
end
示例代码:
Diff:=GetDiffStringLevel('Hello','Hello');// Diff:=0;
Diff:=GetDiffStringLevel('Hello','2Hello');// Diff:=1;
Diff:=GetDiffStringLevel('Hello','H2ello');// Diff:=1;
Diff:=GetDiffStringLevel('Hello','Hello W');// Diff:=2;
Diff:=GetDiffStringLevel('Hello','World');// Diff:=6; or 5