if语句检查字符串

编程入门 行业动态 更新时间:2024-10-11 05:20:16
本文介绍了if语句检查字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我试图确定两个不同的字符串是否与

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语句检查字符串

本文发布于:2023-11-12 13:30:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   语句

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!