所以我试图确定两个不同的字符串是否与
So I'm trying to determine if two different strings are the same with
if DerobModel.ConstructionCount > 22 then begin for i := 22 to DerobModel.ConstructionCount-1 do begin ConstructionName[i] := DerobModel.Constructions[i].Name; ShowMessage(ConstructionName[i]); ShowMessage(DerobModel.HouseProperties.StringValue['NWall']); if ConstructionName[i]=DerobModel.HouseProperties.StringValue['NWall'] then begin ShowMessage('Hej'); igSurf[0]:=idWallCon[i]; end; LayerCount[i] := DerobModel.Constructions[i].LayerCount; idWallCon[i] := i+1; end; end;两个字符串的ShowMessage返回相同的字符串,但不知何故不会在if声明。任何想法?
The ShowMessage for both of the strings returns the same string but somehow it won't go in the if statement. Any ideas?
推荐答案你的字符串是不同的,简单的。 如果你想弄清楚什么是不同的,你可以写一个其他块部分来比较字符串的详细信息,并显示出什么是不同的。
Your strings are different, simple as that. If you want to figure out what exactly is different, you could write an else block portion to compare the strings in detail and show you exactly what is different.
if ConstructionName[i]=DerobModel.HouseProperties.StringValue['NWall'] then begin ShowMessage('Hej'); igSurf[0]:=idWallCon[i]; end else begin if (Length(ConstructionName[i]) <> Length(DerobModel.HouseProperties.StringValue['NWall'])) then begin ShowMessage('Length('+IntToStr(Length(ConstructionName[i]))+') <> Length('+ IntToStr(Length(DerobModel.HouseProperties.StringValue['NWall']))+')'); end else begin for LCharPos := 1 to Length(ConstructionName[i]) do begin if (ConstructionName[i][LCharPos] <> DerobModel.HouseProperties.StringValue['NWall'][LCharPos]) then begin //Here you might need to rather show the ordinal values of the //characters to see the difference if they **look** the same due //to the font of the message. ShowMessage('Pos['+IntToStr(LCharPos)+'] "'+ ConstructionName[i][LCharPos]+'" <> "'+ DerobModel.HouseProperties.StringValue['NWall'][LCharPos]+'"'); end; end; end; end;我可以想到的唯一可能会意外地导致相同的字符串被报告为不同的是:如果它们是不同的字符串类型。例如。如果一个是WideString和另一个AnsiString,那么:
The only thing I can think of that might unexpectedly cause "same" strings to be reported as different is: if they are different string types. E.g. if one is WideString and the other AnsiString, then:
- 必须进行一个隐式的转换来做比较。
- 这意味着其中一个字符串将被更改。
- 更改可能导致两个字符串看起来实际上是不同的。
- There would have to be an implicit conversion to do the comparison.
- And this means one of the strings would be changed.
- The change could cause two strings that look the same to actually be different.
更多推荐
if语句检查字符串
发布评论