string 将整数转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1986475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:36:01  来源:igfitidea点击:

Convert Integer Into String

delphistringvariablesintegerlazarus

提问by Nathan Campos

I have a some numbers stored in a Integercalled mode, but I need to use they in a TProcess. For this I need to convert the Integerinto a String, because if I don't do this, I got the error:

我有一些存储在Integer被叫号码中的数字mode,但我需要在TProcess. 为此,我需要将 the 转换Integer为 a String,因为如果我不这样做,则会出现错误:

Incompatible types: got "LongInt" expected "AnsiString"

不兼容的类型:得到“LongInt”预期“AnsiString”

Then I want to know how I can convert a Integerinto a String?

然后我想知道如何将 a 转换Integer为 a String

回答by notnoop

You can use IntToStr:

您可以使用IntToStr

A:=IntToStr(123)

回答by Johannes Herzig

I just did my first steps with a 30day test version of Delphi XE8 and figured out that one has to write e.g.

我刚刚使用 Delphi XE8 的 30 天测试版完成了我的第一步,并发现必须编写例如

  Ticks: integer;
  LabelTicks: TLabel;
  (...)
  LabelTicks.Text:= System.SysUtils.IntToStr( Ticks);

But: The variable 'Ticks' seems to be an object! I did not expect that, but you can also write

但是:变量 'Ticks' 似乎是一个对象!没想到,不过你也可以写

  LabelTicks.Text:= Ticks.ToString;

To me that seems to be much more elegant.

对我来说,这似乎更优雅。