2008年6月1日 星期日

Delphi 字串函數大全

記下來,省得以後找不到

uses StrUtils; 【字符串函数大全】
首部 function AnsiResemblesText(const AText, AOther: string): Boolean;
$[StrUtils.pas
功能 返回两个字符串是否相似
说明 ANSI(American National Standards Institute)美国国家标准协会;不区分大小写
参考 function StrUtils.SoundexProc; var StrUtils.AnsiResemblesProc
例子 CheckBox1.Checked := AnsiResemblesText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiContainsText(const AText, ASubText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
说明 不区分大小写
参考 function StrUtils.AnsiUppercase; function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStartsText(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText开头
说明 不区分大小写
参考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiStartsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiEndsText(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText结尾
说明 不区分大小写
参考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiEndsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiReplaceText(const AText, AFromText, AToText: string):
string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替换成子串AToText的结果
说明 不区分大小写
参考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags
例子 Edit4.Text := AnsiReplaceText(Edit1.Text, Edit2.Text, Edit3.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiMatchText(const AText: string; const AValues: array of
string): Boolean; $[StrUtils.pas
功能 返回字符串数组AValues中是否包含字符串AText
说明 不区分大小写
参考 function StrUtils.AnsiIndexText
例子 CheckBox1.Checked := AnsiMatchText(Edit1.Text, ['a1', 'a2', 'a3',
'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiIndexText(const AText: string; const AValues: array of
string): Integer; $[StrUtils.pas
功能 返回字符串AText在字符串数组AValues中的位置
说明 不区分大小写;如果不包含则返回-1
参考 function SysUtils.AnsiSameText
例子 SpinEdit1.Value := AnsiIndexText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiContainsStr(const AText, ASubText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
说明 区分大小写
参考 function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStartsStr(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText开头
说明 区分大小写
参考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiStartsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiEndsStr(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText结尾
说明 区分大小写
参考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiEndsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiReplaceStr(const AText, AFromText, AToText: string):
string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替换成子串AToText的结果
说明 区分大小写
参考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags
例子 Edit4.Text := AnsiReplaceStr(Edit1.Text, Edit2.Text, Edit3.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiMatchStr(const AText: string; const AValues: array of
string): Boolean; $[StrUtils.pas
功能 返回字符串数组AValues中是否包含字符串AText
说明 区分大小写
参考 function StrUtils.AnsiIndexStr
例子 CheckBox1.Checked := AnsiMatchStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiIndexStr(const AText: string; const AValues: array of
string): Integer; $[StrUtils.pas
功能 返回字符串AText在字符串数组AValues中的位置
说明 区分大小写
参考 function SysUtils.AnsiSameStr
例子 SpinEdit1.Value := AnsiIndexStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function DupeString(const AText: string; ACount: Integer): string;
$[StrUtils.pas
功能 返回字符串AText的ACount个复本
说明 当ACount为0时返回''
参考 function System.SetLength
例子 Edit3.Text := DupeString(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function ReverseString(const AText: string): string; $ [StrUtils.pas
功能 返回字符串AText的反序
说明 ReverseString('1234') = '4321'
参考 function System.SetLength
例子 Edit3.Text := ReverseString(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StuffString(const AText: string; AStart, ALength: Cardinal;
const ASubText: string): string; $[StrUtils.pas
功能 返回嵌套字符串
说明 AStart:嵌套开始位置;ALength:嵌套长度;StuffString('abcd', 2, 0, '12') = 'a12bcd'
参考 function System.Copy
例子 Edit3.Text := StuffString(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value,
Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function RandomFrom(const AValues: array of string): string; overload;
$[StrUtils.pas
功能 随机返回字符串数组AValues中的一个元素
说明 之前建议执行Randomize
参考 function System.Random
例子 Randomize; Edit3.Text := RandomFrom(['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function IfThen(AValue: Boolean; const ATrue: string; AFalse: string =
''): string; overload; $[StrUtils.pas
功能 返回指定的逻辑字符串
说明 IfThen(True, '是', '否') = '是';IfThen(False, '是', '否') = '否'
参考
例子 Edit3.Text := IfThen(CheckBox1.Checked, Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function LeftStr(const AText: string; const ACount: Integer): string;
$[StrUtils.pas
功能 返回字符串AText左边的ACount个字符
说明 LeftStr('123456', 3) = '123'
参考 function System.Copy
例子 Edit3.Text := LeftStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function RightStr(const AText: string; const ACount: Integer): string;
$[StrUtils.pas
功能 返回字符串AText右边的ACount个字符
说明 RightStr('123456', 3) = '456'
参考 function System.Copy
例子 Edit3.Text := RightStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function MidStr(const AText: string; const AStart, ACount: Integer):
string; $[StrUtils.pas
功能 返回字符串AText从AStart开始的ACount个字符
说明 其实就是Copy
参考 function System.Copy
例子 Edit3.Text := MidStr(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength:
Integer; SearchString: String; Options: TStringSearchOptions = [soDown]):
PChar; $[StrUtils.pas
功能 返回第一个搜索到的指针位置
说明 这函数常用于文本中搜索字符串
参考
例子
///////Begin SearchBuf
function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
SearchOptions: TStringSearchOptions; FindFirst: Boolean = False): Boolean;
var
Buffer, P: PChar;
Size: Word;
begin
Result := False;
if (Length(SearchString) = 0) then Exit;
Size := EditControl.GetTextLen;
if (Size = 0) then Exit;
Buffer := StrAlloc(Size + 1);
try
EditControl.GetTextBuf(Buffer, Size + 1);
P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength,
SearchString, SearchOptions);
if P <> nil then begin
EditControl.SelStart := P - Buffer;
EditControl.SelLength := Length(SearchString);
Result := True;
end;
finally
StrDispose(Buffer);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SearchOptions: TStringSearchOptions;
begin
SearchOptions := [];
if CheckBox1.Checked then
Include(SearchOptions, soDown);
if CheckBox2.Checked then
Include(SearchOptions, soMatchCase);
if CheckBox3.Checked then
Include(SearchOptions, soWholeWord);
SearchEdit(Memo1, Edit1.Text, SearchOptions);
Memo1.SetFocus;
end;
///////End SearchBuf
━━━━━━━━━━━━━━━━━━━━━
首部 function Soundex(const AText: string; ALength: TSoundexLength = 4):
string; $[StrUtils.pas
功能 返回探测字符串
说明 根据探测法(Soundex)可以找到相进的字符串;
参考
例子 Edit2.Text := Soundex(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexInt(const AText: string; ALength: TSoundexIntLength =
4): Integer; $[StrUtils.pas
功能 返回探测整数
说明 ALength的值越大解码准确率越高
参考
例子 SpinEdit2.Value := SoundexInt(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function DecodeSoundexInt(AValue: Integer): string; $ [StrUtils.pas
功能 返回探测整数的解码
说明 DecodeSoundexInt(SoundexInt('hello')) 相当于 Soundex('hello')
参考
例子 Edit2.Text := DecodeSoundexInt(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexWord(const AText: string): Word; $[StrUtils.pas
功能 返回探测文字数值
说明 没有参数ALength已经固定为4
参考
例子 SpinEdit2.Value := SoundexWord(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function DecodeSoundexWord(AValue: Word): string; $ [StrUtils.pas
功能 返回探测文字数值的解码
说明 DecodeSoundexWord(SoundexWord('hello')) 相当于 Soundex('hello')
参考
例子 Edit2.Text := DecodeSoundexWord(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexSimilar(const AText, AOther: string; ALength:
TSoundexLength = 4): Boolean; $[StrUtils.pas
功能 返回两个字符串的探测字符串是否相同
说明 Result := Soundex(AText, ALength) = Soundex(AOther, ALength)
参考
例子 CheckBox1.Checked := SoundexSimilar(Edit1.Text, Edit2.Text,
SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexCompare(const AText, AOther: string; ALength:
TSoundexLength = 4): Integer; $[StrUtils.pas
功能 返回比较两个字符串的探测字符串的结果
说明 Result := AnsiCompareStr(Soundex(AText, ALength), Soundex (AOther,
ALength))
参考 function SysUtils.AnsiCompareStr
例子 SpinEdit2.Value := SoundexCompare(Edit1.Text, Edit2.Text,
SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexProc(const AText, AOther: string): Boolean;
$[StrUtils.pas
功能 调用SoundexSimilar返回两个字符串的探测字符串是否相同
说明 系统变量AnsiResemblesProc的默认值
参考 function StrUtils.AnsiResemblesText
例子 [var AnsiResemblesProc: TCompareTextProc = SoundexProc;]
━━━━━━━━━━━━━━━━━━━━━
首部 function NewStr(const S: string): PString; deprecated; $ [SysUtils.pas
功能 返回一个新的字符串指针地址
说明 字符串S为空时返回NullStr
参考 procedure System.New
例子
////////Begin NewStr,DisposeStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PString;
begin
P := NewStr(Edit1.Text);
Edit2.Text := P^;
DisposeStr(P);
end;
////////End NewStr,DisposeStr
━━━━━━━━━━━━━━━━━━━━━
首部 procedure DisposeStr(P: PString); deprecated; $[SysUtils.pas
功能 释放字符串指针P资源
说明 配合函数NewStr使用
参考 procedure System.Dispose
例子 <如上参见,如下参见>
━━━━━━━━━━━━━━━━━━━━━
首部 procedure AssignStr(var P: PString; const S: string); deprecated;
$[SysUtils.pas
功能 将字符串S更新给字符串指针P
说明 更新值时会释放以前字符串指针的资源
参考 function SysUtils.NewStr;function SysUtils.DisposeStr
例子
////////Begin AssignStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PString;
begin
P := nil;
AssignStr(P, Edit1.Text);
Edit2.Text := P^;
DisposeStr(P);
end;
////////End AssignStr
━━━━━━━━━━━━━━━━━━━━━
首部 procedure AppendStr(var Dest: string; const S: string); deprecated;
$[SysUtils.pas
功能 在字符串Dest后追加字符串S
说明 相当于Dest := Dest + S;Delphi6已经不建议使用
参考
例子
////////Begin AppendStr
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
begin
S := Edit2.Text;
AppendStr(S, Edit1.Text);
Edit2.Text := S;
end;
////////End AppendStr
━━━━━━━━━━━━━━━━━━━━━
首部 function UpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大写形式
说明 非小写字符不处理
参考 procedure System.SetLength
例子 Edit2.Text := UpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function LowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小写形式
说明 非大写字符不处理
参考 procedure System.SetLength
例子 Edit2.Text := LowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function CompareStr(const S1, S2: string): Integer; $ [SysUtils.pas
功能 返回比较两个字符
说明 当S1>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写>
例子 SpinEdit1.Value := CompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
assembler; $[SysUtils.pas
功能 返回比较两个内存指针
说明 CompareMem(PChar('12a'), PChar('12c'), 2)=True;CompareMem(PChar ('12a'),
PChar('12c'), 3)=False
参考
例子 CheckBox1.Checked := CompareMem(Self, Form1, 8);
━━━━━━━━━━━━━━━━━━━━━
首部 function CompareText(const S1, S2: string): Integer; $ [SysUtils.pas
功能 返回比较两个字符串
说明 不区分大小写
参考
例子 SpinEdit1.Value := CompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function SameText(const S1, S2: string): Boolean; $ [SysUtils.pas
功能 返回两个字符串是否相等
说明 不区分大小写
参考
例子 CheckBox1.Checked := SameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiUpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大写形式
说明 ANSI(American National Standards Institute)美国国家标准协会;非小写的字符不变
参考 function Windows.CharUpperBuff
例子 Edit2.Text := AnsiUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiLowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小写形式
说明 非大写字符不处理
参考 function Windows.CharLowerBuff
例子 Edit2.Text := AnsiLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiCompareStr(const S1, S2: string): Integer; $ [SysUtils.pas
功能 反回比较两个字符串
说明 当S1>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写>S2返回值>0;当S1<0;当s1=s2返回值=0;不区分大小写>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写>S2返回值>0;当S1<0;当s1=s2返回值=0;不区分大小写;ignore(忽>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写;length(长>S2返回值>0;当S1<0;当s1=s2返回值=0;不区分大小写>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写>S2返回值>0;当S1<0;当s1=s2返回值=0;不区分大小写 ttextlinebreakstyle =" {$IFDEF">
━━━━━━━━━━━━━━━━━━━━━
首部 function IsValidIdent(const Ident: string): Boolean; $ [SysUtils.pas
功能 返回字符串Ident是否是正确的标识符
说明 标识符::字母|下划线[字母|下划线|数字]...
参考
例子 CheckBox1.Checked := IsValidIdent(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function IntToStr(Value: Integer): string; overload; $ [SysUtils.pas
首部 function IntToStr(Value: Int64): string; overload; $ [SysUtils.pas
功能 返回整数Value转换成字符串
说明 Format('%d', [Value])
参考 function SysUtils.FmtStr
例子 Edit2.Text := IntToStr(SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function IntToHex(Value: Integer; Digits: Integer): string; overload;
$[SysUtils.pas
首部 function IntToHex(Value: Int64; Digits: Integer): string; overload;
$[SysUtils.pas
功能 返回整数Value转换成十六进制表现结果;Format('%.*x', [Digits, Value])
说明 参数Digits指定字符最小宽度;最小宽度不足时将用0填充
参考 function SysUtils.FmtStr
例子 Edit2.Text := IntToHex(SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToInt(const S: string): Integer; $[SysUtils.pas
功能 返回字符串S转换成整数
说明 字符串非整数表达时将引起异常
参考 procedure System.Val
例子 SpinEdit1.Value := StrToInt(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToIntDef(const S: string; Default: Integer): Integer;
$[SysUtils.pas
功能 返回字符串S转换成整数
说明 字符串非整数表达时则返回默认值Default
参考 procedure System.Val
例子 SpinEdit1.Value := StrToIntDef(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
首部 function TryStrToInt(const S: string; out Value: Integer): Boolean;
$[SysUtils.pas
功能 返回字符串S转换成整数Value是否成功
说明 字符串非整数表达时返回False并且Value将输出为0

nbsp; 参考 procedure System.Val
例子
///////Begin TryStrToInt
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
CheckBox1.Checked := TryStrToInt(Edit1.Text, I);
SpinEdit1.Value := I;
end;
///////End TryStrToInt
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToInt64(const S: string): Int64; $[SysUtils.pas
功能 返回字符串S转换成六十四位整数
说明 字符串非六十四位整数表达时将引起异常
参考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToInt64Def(const S: string; const Default: Int64): Int64;
$[SysUtils.pas
功能 返回字符串S转换成六十四位整数
说明 字符串非六十四位整数表达时则返回默认值Default
参考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64Def(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
首部 function TryStrToInt64(const S: string; out Value: Int64): Boolean;
$[SysUtils.pas
功能 返回字符串S转换成六十四位整数Value是否成功
说明 字符串非六十四位整数表达时返回False并且Value将输出为0
参考 procedure System.Val
例子
///////Begin TryStrToInt64
procedure TForm1.Button1Click(Sender: TObject);
var
I: Int64;
begin
CheckBox1.Checked := TryStrToInt64(Edit1.Text, I);
SpinEdit1.Value := I;
end;
///////End TryStrToInt64
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToBool(const S: string): Boolean; $[SysUtils.pas
功能 返回字符串S转换成逻辑值
说明 字符非逻辑表达时将引起异常
参考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBool(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToBoolDef(const S: string; const Default: Boolean):
Boolean; $[SysUtils.pas
功能 返回字符串S转换成逻辑值
说明 字符非逻辑表达时则返回默认值Default
参考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBoolDef(Edit1.Text, False);
━━━━━━━━━━━━━━━━━━━━━
首部 function TryStrToBool(const S: string; out Value: Boolean): Boolean;
$[SysUtils.pas
功能 返回字符串S转换成逻辑值Value是否成功
说明 [注意]0为假非0为真;不是'True'和'False';Delphi6 Bug 如下修正
参考 function SysUtils.AnsiSameText;var SysUtils.TrueBoolStrs;var
SysUtils.FalseBoolStrs
例子
///////Begin TryStrToBool
procedure TForm1.Button1Click(Sender: TObject);
var
B: Boolean;
begin
SetLength(TrueBoolStrs, 2);
SetLength(FalseBoolStrs, 2);
TrueBoolStrs[0] := 'True';
FalseBoolStrs[0] := 'False';
TrueBoolStrs[1] := 'Yes';
FalseBoolStrs[1] := 'No';
CheckBox1.Checked := TryStrToBool(Edit1.Text, B);
CheckBox2.Checked := B;
end;
///////End TryStrToBool
附加
///////Begin TryStrToBool
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
function CompareWith(const aArray: array of string): Boolean;
var
I: Integer;
begin
Result := False;
for I := Low(aArray) to High(aArray) do
if AnsiSameText(S, aArray[I]) then
begin
Result := True;
Break;
end;
end;
var
LResult: Extended;
begin
Result := TryStrToFloat(S, LResult);
if Result then
Value := LResult <> 0
else
begin
Result := True; //修正处
VerifyBoolStrArray;
if CompareWith(TrueBoolStrs) then
Value := True
else if CompareWith(FalseBoolStrs) then
Value := False
else
Result := False;
end;
end;
///////End TryStrToBool
━━━━━━━━━━━━━━━━━━━━━
首部 function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;
$[SysUtils.pas
功能 返回逻辑值B转换成字符串
说明 BoolToStr(False, False)='0';BoolToStr(False, True)='-1'
参考 var SysUtils.TrueBoolStrs;var SysUtils.FalseBoolStrs
例子 Edit1.Text := BoolToStr(CheckBox1.Checked, CheckBox2.Checked);
━━━━━━━━━━━━━━━━━━━━━
首部 function LoadStr(Ident: Integer): string; $[SysUtils.pas
功能 返回根据标识Ident的字符串资源
说明 字符串资源是指程序的内部资源
参考 function SysUtils.FindStringResource
例子 Edit2.Text := LoadStr(StrToIntDef(Edit1.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
首部 function FmtLoadStr(Ident: Integer; const Args: array of const):
string; $[SysUtils.pas
功能 返回格式化的字符串资源
说明 字符串资源是指程序的内部资源
参考 function SysUtils.FmtStr;function SysUtils.FindStringResource
例子 ;
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLen(const Str: PChar): Cardinal; $[SysUtils.pas
功能 返回指针字符串的长度
说明 当指针字符串Str为nil时将触发异常
参考
例子 SpinEdit2.Value := StrLen(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function StrEnd(const Str: PChar): PChar; $[SysUtils.pas
功能 返回指针字符串的结尾
说明 当指针字符串Str为nil时将触发异常
参考
例子 Edit2.Text := StrEnd(PChar(Edit1.Text)) - SpinEdit1.Value;
━━━━━━━━━━━━━━━━━━━━━
首部 function StrMove(Dest: PChar; const Source: PChar; Count: Cardinal):
PChar; $[SysUtils.pas
功能 返回将指针字符串Source指定内存数量Count复制覆盖到指针字符串Dest中
说明 Dest没有分配资源将触发异常s
参考 function System.Move
例子
///////Begin StrMove
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: PChar;
begin
vBuffer := '0123456789';
StrMove(vBuffer, PChar(Edit1.Text), SpinEdit1.Value);
Edit2.Text := vBuffer;
end;
///////End StrMove
━━━━━━━━━━━━━━━━━━━━━
首部 function StrCopy(Dest: PChar; const Source: PChar): PChar;
$[SysUtils.pas
功能 返回将指针字符串Source复制到指针字符串Dest中; 说明 Dest应已经分配足够的空间非则将触发异常
参考
例子
///////Begin StrCopy
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: PChar;
begin
GetMem(vBuffer, Length(Edit1.Text) + 1);
StrCopy(vBuffer, PChar(Edit1.Text));
Edit2.Text := vBuffer;
FreeMem(vBuffer);
end;
///////End StrCopy
━━━━━━━━━━━━━━━━━━━━━
首部 function StrECopy(Dest:PChar; const Source: PChar): PChar;
$[SysUtils.pas
功能 返回将指针字符串Source复制到指针字符串Dest中的结尾
说明 可以连接指针字符串
参考
例子
///////Begin StrECopy
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
begin
StrECopy(StrECopy(vBuffer, PChar(Edit1.Text)), PChar(Edit2.Text));
Edit3.Text := vBuffer;
end;
///////End StrECopy
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal):
PChar; $[SysUtils.pas
功能 返回将指针字符串Source指定长度MaxLen复制到指针字符串Dest中
说明 Dest应已经分配足够的空间非则将触发异常
参考
例子
///////Begin StrLCopy
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
begin
StrLCopy(vBuffer, PChar(Edit1.Text), SpinEdit1.Value);
Edit2.Text := vBuffer;
end;
///////End StrLCopy
━━━━━━━━━━━━━━━━━━━━━
首部 function StrPCopy(Dest: PChar; const Source: string): PChar;
$[SysUtils.pas
功能 返回将指针字符串Source粗频街刚胱址瓺est中
说明 StrLCopy(Dest, PChar(Source), Length(Source))
参考 function SysUtils.StrLCopy
例子
///////Begin StrPCopy
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
begin
StrPCopy(vBuffer, PChar(Edit1.Text));
Edit2.Text := vBuffer;
end;
///////End StrPCopy
━━━━━━━━━━━━━━━━━━━━━
首部 function StrPLCopy(Dest: PChar; const Source: string; MaxLen:
Cardinal): PChar; $[SysUtils.pas
功能 返回将字符串Source指定长度MaxLen复制到指针字符串Dest中
说明 StrLCopy(Dest, PChar(Source), MaxLen)
参考 function SysUtils.StrLCopy
例子
///////Begin StrPLCopy
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
begin
StrPLCopy(vBuffer, Edit1.Text, SpinEdit1.Value);
Edit2.Text := vBuffer;
end;
///////End StrPLCopy
━━━━━━━━━━━━━━━━━━━━━
首部 function StrCat(Dest: PChar; const Source: PChar): PChar;
$[SysUtils.pas
功能 返回连接指针字符串Dest和指针字符串Source
说明 StrCopy(StrEnd(Dest), Source)
参考 function SysUntils.StrCopy
例子
///////Begin StrCat
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
begin
StrPCopy(vBuffer, Edit1.Text);
StrCat(vBuffer, PChar(Edit2.Text));
Edit3.Text := vBuffer;
end;
///////End StrCat
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLCat(Dest: PChar; const Source: PChar; MaxLen: Cardinal):
PChar; $[SysUtils.pas
功能 返回连接指针字符串Dest和指针字符串Source
说明 [注意]MaxLen指定连接后的最大长度不是指针字符串Source的长度
参考
例子
///////Begin StrLCat
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
begin
StrPCopy(vBuffer, Edit1.Text);
StrLCat(vBuffer, PChar(Edit2.Text), SpinEdit1.Value);
Edit3.Text := vBuffer;
end;
///////End StrLCat
━━━━━━━━━━━━━━━━━━━━━
首部 function StrComp(const Str1, Str2: PChar): Integer; $ [SysUtils.pas
功能 返回比较两个指针字符串
说明 当S1>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写;[注意]返回第一个>
例子 SpinEdit1.Value := StrComp(PChar(Edit1.Text), PChar (Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function StrIComp(const Str1, Str2: PChar): Integer; $ [SysUtils.pas
功能 返回比较两个指针字符串
说明 当S1>S2返回值>0;当S1<0;当s1=s2返回值=0;不区分大小写;[注意]返回第一>
例子 SpinEdit1.Value := StrIComp(PChar(Edit1.Text), PChar (Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;
$[SysUtils.pas
功能 返回比较两个指针字符串指定长度
说明 当S1>S2返回值>0;当S1<0;当s1=s2返回值=0;区分大小写;length(长>
例子 SpinEdit1.Value := StrLComp(PChar(Edit1.Text), PChar (Edit2.Text),
SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLIComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;
$[SysUtils.pas
功能 返回比较两个指针字符串指定长度
说明 当S1>S2返回值>0;当S1<0;当s1=s2返回值=0;不区分大小写;[注意]返回第一>
例子 SpinEdit1.Value := StrLIComp(PChar(Edit1.Text), PChar (Edit2.Text),
SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
首部 function StrScan(const Str: PChar; Chr: Char): PChar; $ [SysUtils.pas
功能 返回在指针字符串Str搜索字符Chr第一个出现的地址
说明 没有找到则返回空指针
参考
例子 Edit2.Text := StrScan(PChar(Edit1.Text), '*');
━━━━━━━━━━━━━━━━━━━━━
首部 function StrRScan(const Str: PChar; Chr: Char): PChar; $ [SysUtils.pas
功能 返回在指针字符串Str搜索字符Chr最后一个出现的地址
说明 没有找到则返回空指针
参考
例子 Edit2.Text := StrRScan(PChar(Edit1.Text), '*');
━━━━━━━━━━━━━━━━━━━━━
首部 function StrPos(const Str1, Str2: PChar): PChar; $[SysUtils.pas
功能 返回指针字符串Str2在Str1中第一个出现的地址
说明 没有找到则返回空指针;StrPos('12345', '3') = '345'
参考
例子 Edit3.Text := StrPos(PChar(Edit1.Text), PChar(Edit2.Text))

沒有留言: