发信人: mendy.bbs@bbs.nju.edu.cn (孟迪), 信区: cnprogram
标 题: string manipulation routines
发信站: nju_bbs (Sun Apr 19 09:21:07 1998)
转信站: Lilac!ustcnews!nju_bbs
发信人: njhe (he要破产), 信区: RAD
标 题: string manipulation routines
发信站: '3m紫金飞鸿m' (Mon Mar 9 18:13:37 1998) , 站内信件
Product: Delphi
Version: All
Platform: Windows/Win32
Here are some standard string manipulation functions:
{To determine if the character is a digit.}
function IsDigit(ch: char): boolean;
begin
Result := ch in ['0'..'9'];
end;
{To determine if the character is an uppercase letter.}
function IsUpper(ch: char): boolean;
begin
Result := ch in ['A'..'Z'];
end;
{To determine if the character is an lowercase letter.}
function IsLower(ch: char): boolean;
begin
Result := ch in ['a'..'z'];
end;
{Changes a character to an uppercase letter.}
function ToUpper(ch: char): char;
begin
Result := chr(ord(ch) and $DF);
end;
{Changes a character to a lowercase letter.}
function ToLower(ch: char): char;
begin
Result := chr(ord(ch) or $20);
end;
{ Capitalizes first letter of every word in s }
function Proper(const s: string): string;
var
i: Integer;
CapitalizeNextLetter: Boolean;
begin
Result := LowerCase(s);
CapitalizeNextLetter := True;
for i := 1 to Length(Result) do
begin
if CapitalizeNextLetter and IsLower(Result[i]) then
Result[i] := ToUpper(Result[i]);
CapitalizeNextLetter := Result[i] = ' ';
end;
end;
{ NOTE: The following functions are available in Delphi 2.0,
but not in Delphi 1.0. }
{Supresses trailing blanks in a string.}
function TrimRight(const s: string): string;
var
i: integer;
begin
i := Length(s);
while (I > 0) and (s[i] <= ' ') do Dec(i);
Result := Copy(s, 1, i);
end;
{Removes the leading spaces from a string.}
function TrimLeft(const S: string): string;
var
I, L: Integer;
begin
L := Length(S);
I := 1;
while (I <= L) and (S[I] <= ' ') do Inc(I);
Result := Copy(S, I, Maxint);
end;
{ Removes leading and trailing whitespace from s);
function Trim(const S: string): string;
var
I, L: Integer;
begin
L := Length(S);
I := 1;
while (I <= L) and (S[I] <= ' ') do Inc(I);
if I > L then Result := '' else
begin
while S[L] <= ' ' do Dec(L);
Result := Copy(S, I, L - I + 1);
end;
end;
--
不惜一切代价,达到修炼的真义。
遇神阻则弑神,遇佛阻则弑佛。
m;31m※ 来源:·紫金飞鸿 bbs.njupt.edu.cn·[FROM: 202.119.236.104]m
--
※ 来源:.南大小百合信息交换站 bbs.nju.edu.cn.[FROM: a507yjh.nju.edu]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:6.047毫秒