请教:str函数怎么用(50分)

  • 主题发起人 主题发起人 lanpx
  • 开始时间 开始时间
L

lanpx

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:

str函数怎么用,[:D] 最好能举一个例子
谢谢了
 
有点Format的效果,在变量中返回格式化的字符串:
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
str(10,s);
showmessage('['+s+']');
//s='10'
str(10.15:5:1,s);
showmessage('['+s+']');
//s=' 10.2'
end;
 
Formats a string and returns it to a variable.
Unit
System
Category
string handling routines
procedure Str(X [: Width [: Decimals ]];
var S);
Description
Str converts X to a string representation according to the Width and Decimals formatting parameters. The effect is like a call to Write except the resulting string is stored in S instead of being written to a text file.
X is an integer-type or real-type expression. Width and Decimals are integer-type expressions. S is a string-type variable or a zero-based character array variable if extended syntax is enabled.

function MakeItAString(I: Longint): string;
{ Convert any integer type to a string }
var
S: string[11];
begin
Str(I, S);
Result:= S;
end;

begin
Canvas.TextOut(10, 10, MakeItAString(-5322));
end;
 
多人接受答案了。
 
后退
顶部