Groups
Groups
Sign in
Groups
Groups
编程笔记
Conversations
About
Send feedback
Help
Delphi里去掉字符串中空格的函数是什么?
21 views
Skip to first unread message
william
unread,
Jan 5, 2008, 10:21:26 PM
1/5/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 编程笔记
Q :--Delphi里去掉字符串中空格的函数是什么?
Re:
Trim()去掉字符串左右两边的空格和控制符,它的使用语法如下:
function Trim(const S: string): string;
TrimLeft()用于去除字符串左边的空格,它的使用方法如下:
function TrimLeft(const S: string): string;
TrimRight()用于去除字符串右边的空格,它的使用方法如下:
function TrimRight(const S: string): string;
如果要去除字符串中间的空格就需要自己写程序来实现了,下面提供了一种方法,其主要思路是利用Pos()函数得到空格所在整个字符串中的位置,然后
以此位置为界把整个字符串分别存到两个变量中,然后Trim掉有空格的那一部分,在把两个字符串合并,然后重复上述过程,直到Pos()函数返回0也就
是没有找到空格为止。
Q :--Delphi中如何得到程序的路径?
Re:
使用如下的语句即可:
ExtractFilePath(Application.ExeName)
ExtractFileDir(Application.Exename)
它们分别用来获取应用程序的路径名,但前者其结尾字符总是“\”;而后者不返回“\”;除非是在根目录下,程序举例如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ExtractFileDir(Application.Exename)); // 如: c:\temp
ShowMessage(ExtractFilePath(Application.Exename)); // 如: c:\temp
\
end;
Q :--Delphi中怎么将实数取整?
Re:
floor 和 ceil 是 math unit 里的函数,使用前要先 Uses Math。
trunc 和 round 是 system unit 里的函数,缺省就可以用。
floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123
trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123
ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124
round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124
Reply all
Reply to author
Forward
0 new messages