轉(zhuǎn):http://chinaitpower.net/A/2005-01-18/105341.html
uses StrUtils;【字符串函數(shù)大全】
首部 function AnsiResemblesText(const AText, AOther: string): Boolean;
$[StrUtils.pas
功能 返回兩個(gè)字符串是否相似
說(shuō)明 ANSI(American National Standards Institute)美國(guó)國(guó)家標(biāo)準(zhǔn)協(xié)會(huì);不區(qū)分大小寫(xiě)
參考 function StrUtils.SoundexProc; var StrUtils.AnsiResemblesProc
例子 CheckBox1.Checked := AnsiResemblesText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiContainsText(const AText, ASubText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
說(shuō)明 不區(qū)分大小寫(xiě)
參考 function StrUtils.AnsiUppercase; function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStartsText(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText開(kāi)頭
說(shuō)明 不區(qū)分大小寫(xiě)
參考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiStartsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiEndsText(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText結(jié)尾
說(shuō)明 不區(qū)分大小寫(xiě)
參考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiEndsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiReplaceText(const AText, AFromText, AToText: string):
string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替換成子串AToText的結(jié)果
說(shuō)明 不區(qū)分大小寫(xiě)
參考 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
功能 返回字符串?dāng)?shù)組AValues中是否包含字符串AText
說(shuō)明 不區(qū)分大小寫(xiě)
參考 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在字符串?dāng)?shù)組AValues中的位置
說(shuō)明 不區(qū)分大小寫(xiě);如果不包含則返回-1
參考 function SysUtils.AnsiSameText
例子 SpinEdit1.Value := AnsiIndexText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiContainsStr(const AText, ASubText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
說(shuō)明 區(qū)分大小寫(xiě)
參考 function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStartsStr(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText開(kāi)頭
說(shuō)明 區(qū)分大小寫(xiě)
參考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiStartsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiEndsStr(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText結(jié)尾
說(shuō)明 區(qū)分大小寫(xiě)
參考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiEndsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiReplaceStr(const AText, AFromText, AToText: string):
string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替換成子串AToText的結(jié)果
說(shuō)明 區(qū)分大小寫(xiě)
參考 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
功能 返回字符串?dāng)?shù)組AValues中是否包含字符串AText
說(shuō)明 區(qū)分大小寫(xiě)
參考 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在字符串?dāng)?shù)組AValues中的位置
說(shuō)明 區(qū)分大小寫(xiě)
參考 function SysUtils.AnsiSameStr
例子 SpinEdit1.Value := AnsiIndexStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
首部 function DupeString(const AText: string; ACount: Integer): string;
$[StrUtils.pas
功能 返回字符串AText的ACount個(gè)復(fù)本
說(shuō)明 當(dāng)ACount為0時(shí)返回'
參考 function System.SetLength
例子 Edit3.Text := DupeString(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function ReverseString(const AText: string): string; $[StrUtils.pas
功能 返回字符串AText的反序
說(shuō)明 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
功能 返回嵌套字符串
說(shuō)明 AStart:嵌套開(kāi)始位置;ALength:嵌套長(zhǎng)度;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
功能 隨機(jī)返回字符串?dāng)?shù)組AValues中的一個(gè)元素
說(shuō)明 之前建議執(zhí)行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
功能 返回指定的邏輯字符串
說(shuō)明 IfThen(True, '是', '否') = '是';IfThen(False, '是', '否') = '否'
參考 <NULL>
例子 Edit3.Text := IfThen(CheckBox1.Checked, Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function LeftStr(const AText: string; const ACount: Integer): string;
$[StrUtils.pas
功能 返回字符串AText左邊的ACount個(gè)字符
說(shuō)明 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個(gè)字符
說(shuō)明 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開(kāi)始的ACount個(gè)字符
說(shuō)明 其實(shí)就是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
功能 返回第一個(gè)搜索到的指針位置
說(shuō)明 這函數(shù)常用于文本中搜索字符串
參考 <NULL>
例子
///////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
功能 返回探測(cè)字符串
說(shuō)明 根據(jù)探測(cè)法(Soundex)可以找到相進(jìn)的字符串;http://www.nara.gov/genealogy/coding.html
參考 <NULL>
例子 Edit2.Text := Soundex(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexInt(const AText: string; ALength: TSoundexIntLength =
4): Integer; $[StrUtils.pas
功能 返回探測(cè)整數(shù)
說(shuō)明 ALength的值越大解碼準(zhǔn)確率越高
參考 <NULL>
例子 SpinEdit2.Value := SoundexInt(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function DecodeSoundexInt(AValue: Integer): string; $[StrUtils.pas
功能 返回探測(cè)整數(shù)的解碼
說(shuō)明 DecodeSoundexInt(SoundexInt('hello')) 相當(dāng)于 Soundex('hello')
參考 <NULL>
例子 Edit2.Text := DecodeSoundexInt(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexWord(const AText: string): Word; $[StrUtils.pas
功能 返回探測(cè)文字?jǐn)?shù)值
說(shuō)明 沒(méi)有參數(shù)ALength已經(jīng)固定為4
參考 <NULL>
例子 SpinEdit2.Value := SoundexWord(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function DecodeSoundexWord(AValue: Word): string; $[StrUtils.pas
功能 返回探測(cè)文字?jǐn)?shù)值的解碼
說(shuō)明 DecodeSoundexWord(SoundexWord('hello')) 相當(dāng)于 Soundex('hello')
參考 <NULL>
例子 Edit2.Text := DecodeSoundexWord(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexSimilar(const AText, AOther: string; ALength:
TSoundexLength = 4): Boolean; $[StrUtils.pas
功能 返回兩個(gè)字符串的探測(cè)字符串是否相同
說(shuō)明 Result := Soundex(AText, ALength) = Soundex(AOther, ALength)
參考 <NULL>
例子 CheckBox1.Checked := SoundexSimilar(Edit1.Text, Edit2.Text,
SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function SoundexCompare(const AText, AOther: string; ALength:
TSoundexLength = 4): Integer; $[StrUtils.pas
功能 返回比較兩個(gè)字符串的探測(cè)字符串的結(jié)果
說(shuō)明 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
功能 調(diào)用SoundexSimilar返回兩個(gè)字符串的探測(cè)字符串是否相同
說(shuō)明 系統(tǒng)變量AnsiResemblesProc的默認(rèn)值
參考 function StrUtils.AnsiResemblesText
例子 [var AnsiResemblesProc: TCompareTextProc = SoundexProc;]
━━━━━━━━━━━━━━━━━━━━━
首部 function NewStr(const S: string): PString; deprecated; $[SysUtils.pas
功能 返回一個(gè)新的字符串指針地址
說(shuō)明 字符串S為空時(shí)返回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資源
說(shuō)明 配合函數(shù)NewStr使用
參考 procedure System.Dispose
例子 <如上參見(jiàn),如下參見(jiàn)>
━━━━━━━━━━━━━━━━━━━━━
首部 procedure AssignStr(var P: PString; const S: string); deprecated;
$[SysUtils.pas
功能 將字符串S更新給字符串指針P
說(shuō)明 更新值時(shí)會(huì)釋放以前字符串指針的資源
參考 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
說(shuō)明 相當(dāng)于Dest := Dest + S;Delphi6已經(jīng)不建議使用
參考 <NULL>
例子
////////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的大寫(xiě)形式
說(shuō)明 非小寫(xiě)字符不處理
參考 procedure System.SetLength
例子 Edit2.Text := UpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function LowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小寫(xiě)形式
說(shuō)明 非大寫(xiě)字符不處理
參考 procedure System.SetLength
例子 Edit2.Text := LowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function CompareStr(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個(gè)字符
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě)
參考 <NULL>
例子 SpinEdit1.Value := CompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;
assembler; $[SysUtils.pas
功能 返回比較兩個(gè)內(nèi)存指針
說(shuō)明 CompareMem(PChar('12a'), PChar('12c'), 2)=True;CompareMem(PChar('12a'),
PChar('12c'), 3)=False
參考 <NULL>
例子 CheckBox1.Checked := CompareMem(Self, Form1, 8);
━━━━━━━━━━━━━━━━━━━━━
首部 function CompareText(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個(gè)字符串
說(shuō)明 不區(qū)分大小寫(xiě)
參考 <NULL>
例子 SpinEdit1.Value := CompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function SameText(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個(gè)字符串是否相等
說(shuō)明 不區(qū)分大小寫(xiě)
參考 <NULL>
例子 CheckBox1.Checked := SameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiUpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大寫(xiě)形式
說(shuō)明 ANSI(American National Standards Institute)美國(guó)國(guó)家標(biāo)準(zhǔn)協(xié)會(huì);非小寫(xiě)的字符不變
參考 function Windows.CharUpperBuff
例子 Edit2.Text := AnsiUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiLowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小寫(xiě)形式
說(shuō)明 非大寫(xiě)字符不處理
參考 function Windows.CharLowerBuff
例子 Edit2.Text := AnsiLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiCompareStr(const S1, S2: string): Integer; $[SysUtils.pas
功能 反回比較兩個(gè)字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiCompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiSameStr(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個(gè)字符串是否相等
說(shuō)明 區(qū)分大小寫(xiě)
參考 function SysUtils.AnsiCompareStr
例子 CheckBox1.Checked := AnsiSameStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiCompareText(const S1, S2: string): Integer; $[SysUtils.pas
功能 反回比較兩個(gè)字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiCompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiSameText(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個(gè)字符串是否相等
說(shuō)明 不區(qū)分大小寫(xiě)
參考 function SysUtils.AnsiCompareText
例子 CheckBox1.Checked := AnsiSameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrComp(S1, S2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個(gè)指針字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě)
參考 function System.CompareString
例子 SpinEdit1.Value := AnsiStrComp(PChar(Edit1.Text), PChar(Edit2.Text))
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrIComp(S1, S2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個(gè)指針字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě);Ignore(忽略)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrIComp(PChar(Edit1.Text), PChar(Edit2.Text))
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
$[SysUtils.pas
功能 返回比較兩個(gè)指針字符串指定長(zhǎng)度
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě);Length(長(zhǎng)度)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrLComp(PChar(Edit1.Text), PChar(Edit2.Text),
SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
$[SysUtils.pas
功能 返回比較兩個(gè)指針字符串指定長(zhǎng)度
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrLIComp(PChar(Edit1.Text), PChar(Edit2.Text),
SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrLower(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串小寫(xiě)形式
說(shuō)明 非大寫(xiě)字符不處理
參考 function Windows.CharLower
例子 Edit2.Text := AnsiStrLower(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrUpper(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串大寫(xiě)形式
說(shuō)明 非小寫(xiě)字符不處理
參考 function Windows.CharUpper
例子 Edit2.Text := AnsiStrUpper(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiLastChar(const S: string): PChar; $[SysUtils.pas
功能 返回字符串S的最后一個(gè)指針字符
說(shuō)明 當(dāng)字符串S為空串則返回空指針
參考 function SysUtils.ByteType
例子 Edit2.Text := AnsiLastChar(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiStrLastChar(P: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串P的最后一個(gè)指針字符
說(shuō)明 當(dāng)字符串P為空空指針則返回空指針
參考 function SysUtils.ByteType
例子 Edit2.Text := AnsiLastChar(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function WideUpperCase(const S: WideString): WideString; $[SysUtils.pas
功能 返回雙字節(jié)字符串的大寫(xiě)形式
說(shuō)明 WideChar雙字節(jié)字符
參考 function Windows.CharUpperBuffW
例子 Edit2.Text := WideUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function WideLowerCase(const S: WideString): WideString; $[SysUtils.pas
功能 返回雙字節(jié)字符串的小寫(xiě)形式
說(shuō)明 我怎么就測(cè)試不出來(lái)呢
參考 function Windows.CharLowerBuffW
例子 Edit2.Text := WideLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function WideCompareStr(const S1, S2: WideString): Integer;
$[SysUtils.pas
功能 返回比較兩個(gè)雙字節(jié)字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě)
參考 function Windows.CompareStringW
例子 SpinEdit1.Value := WideCompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function WideSameStr(const S1, S2: WideString): Boolean; $[SysUtils.pas
功能 返回兩個(gè)雙字節(jié)字符串是否相同
說(shuō)明 區(qū)分大小寫(xiě)
參考 function SysUtils.WideCompareStr
例子 CheckBox1.Checked := WideSameStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function WideCompareText(const S1, S2: WideString): Integer;
$[SysUtils.pas
功能 返回比較兩個(gè)雙字節(jié)字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě)
參考 function Windows.CompareStringW
例子 SpinEdit1.Value := WideCompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function WideSameText(const S1, S2: WideString): Boolean;
$[SysUtils.pas
功能 返回兩個(gè)雙字節(jié)字符串是否相同
說(shuō)明 不區(qū)分大小寫(xiě)
參考 function SysUtils.WideCompareText
例子 CheckBox1.Checked := WideSameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function Trim(const S: string): string; overload; $[SysUtils.pas
首部 function Trim(const S: WideString): WideString; overload;
$[SysUtils.pas
功能 返回除去字符串S左右不可見(jiàn)字符
說(shuō)明 小于#32的字符看作不可見(jiàn)字符
參考 function System.Copy
例子 Edit2.Text := Trim(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function TrimLeft(const S: string): string; overload; $[SysUtils.pas
首部 function TrimLeft(const S: WideString): WideString; overload;
$[SysUtils.pas
功能 返回除去字符串S左邊不可見(jiàn)字符
說(shuō)明 小于#32的字符看作不可見(jiàn)字符
參考 function System.Copy
例子 Edit2.Text := TrimLeft(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function TrimRight(const S: string): string; overload; $[SysUtils.pas
首部 function TrimRight(const S: WideString): WideString; overload;
$[SysUtils.pas
功能 返回除去字符串S右邊不可見(jiàn)字符
說(shuō)明 小于#32的字符看作不可見(jiàn)字符
參考 function System.Copy
例子 Edit2.Text := TrimRight(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function QuotedStr(const S: string): string; $[SysUtils.pas
功能 返回字符串S在pascal中的表現(xiàn)形式
說(shuō)明 單引號(hào)中的一個(gè)單引號(hào)將轉(zhuǎn)成兩個(gè)
參考 procedure System.Insert
例子 Edit2.Text := QuotedStr(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiQuotedStr(const S: string; Quote: Char): string;
$[SysUtils.pas
功能 返回字符串S以字符Quote為引號(hào)的表現(xiàn)形式
說(shuō)明 AnsiQuotedStr('hello"world',
'@')='@hello"world@';AnsiQuotedStr('hello"world', '"')='"hello""world"'
參考 function SysUtils.AnsiStrScan
例子 Edit2.Text := AnsiQuotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
$[SysUtils.pas
功能 返回以字符Quote為引號(hào)的表現(xiàn)形式原形
說(shuō)明 表現(xiàn)形式非法時(shí)Src不變否則為空
參考 function SysUtils.AnsiStrScan
例子
///////Begin AnsiExtractQuotedStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PChar;
begin
P := PChar(Edit1.Text);
Edit2.Text := AnsiExtractQuotedStr(P, '"');
Edit3.Text := P;
end;
///////End AnsiExtractQuotedStr
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiDequotedStr(const S: string; AQuote: Char): string;
$[SysUtils.pas
功能 返回以字符AQuote為引號(hào)的表現(xiàn)形式原形
說(shuō)明 表現(xiàn)形式非法時(shí)則返回S
參考 function SysUtils.AnsiExtractQuotedStr
例子 Edit2.Text := AnsiDequotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
首部 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle =
{$IFDEF LINUX} tlbsLF {$ENDIF} {$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}):
string; $[SysUtils.pas
功能 返回將給定字符串的行分隔符調(diào)整為CR/LF序列
說(shuō)明
AdjustLineBreaks('1'#13'2'#13)='1'#13#10'2'#13#10;AdjustLineBreaks('1'#10'2'#10)='1'#13#10'2'#13#10
參考 function SysUtils.StrNextChar
例子 <NULL>
━━━━━━━━━━━━━━━━━━━━━
首部 function IsValidIdent(const Ident: string): Boolean; $[SysUtils.pas
功能 返回字符串Ident是否是正確的標(biāo)識(shí)符
說(shuō)明 標(biāo)識(shí)符::字母|下劃線[字母|下劃線|數(shù)字]...
參考 <NULL>
例子 CheckBox1.Checked := IsValidIdent(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function IntToStr(Value: Integer): string; overload; $[SysUtils.pas
首部 function IntToStr(Value: Int64): string; overload; $[SysUtils.pas
功能 返回整數(shù)Value轉(zhuǎn)換成字符串
說(shuō)明 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
功能 返回整數(shù)Value轉(zhuǎn)換成十六進(jìn)制表現(xiàn)結(jié)果;Format('%.*x', [Digits, Value])
說(shuō)明 參數(shù)Digits指定字符最小寬度;最小寬度不足時(shí)將用0填充
參考 function SysUtils.FmtStr
例子 Edit2.Text := IntToHex(SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToInt(const S: string): Integer; $[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成整數(shù)
說(shuō)明 字符串非整數(shù)表達(dá)時(shí)將引起異常
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToIntDef(const S: string; Default: Integer): Integer;
$[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成整數(shù)
說(shuō)明 字符串非整數(shù)表達(dá)時(shí)則返回默認(rèn)值Default
參考 procedure System.Val
例子 SpinEdit1.Value := StrToIntDef(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
首部 function TryStrToInt(const S: string; out Value: Integer): Boolean;
$[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成整數(shù)Value是否成功
說(shuō)明 字符串非整數(shù)表達(dá)時(shí)返回False并且Value將輸出為0
參考 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轉(zhuǎn)換成六十四位整數(shù)
說(shuō)明 字符串非六十四位整數(shù)表達(dá)時(shí)將引起異常
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToInt64Def(const S: string; const Default: Int64): Int64;
$[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成六十四位整數(shù)
說(shuō)明 字符串非六十四位整數(shù)表達(dá)時(shí)則返回默認(rèn)值Default
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64Def(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
首部 function TryStrToInt64(const S: string; out Value: Int64): Boolean;
$[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成六十四位整數(shù)Value是否成功
說(shuō)明 字符串非六十四位整數(shù)表達(dá)時(shí)返回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轉(zhuǎn)換成邏輯值
說(shuō)明 字符非邏輯表達(dá)時(shí)將引起異常
參考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBool(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function StrToBoolDef(const S: string; const Default: Boolean):
Boolean; $[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成邏輯值
說(shuō)明 字符非邏輯表達(dá)時(shí)則返回默認(rèn)值Default
參考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBoolDef(Edit1.Text, False);
━━━━━━━━━━━━━━━━━━━━━
首部 function TryStrToBool(const S: string; out Value: Boolean): Boolean;
$[SysUtils.pas
功能 返回字符串S轉(zhuǎn)換成邏輯值Value是否成功
說(shuō)明 [注意]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轉(zhuǎn)換成字符串
說(shuō)明 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
功能 返回根據(jù)標(biāo)識(shí)Ident的字符串資源
說(shuō)明 字符串資源是指程序的內(nèi)部資源
參考 function SysUtils.FindStringResource
例子 Edit2.Text := LoadStr(StrToIntDef(Edit1.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
首部 function FmtLoadStr(Ident: Integer; const Args: array of const):
string; $[SysUtils.pas
功能 返回格式化的字符串資源
說(shuō)明 字符串資源是指程序的內(nèi)部資源
參考 function SysUtils.FmtStr;function SysUtils.FindStringResource
例子 <NULL>;
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLen(const Str: PChar): Cardinal; $[SysUtils.pas
功能 返回指針字符串的長(zhǎng)度
說(shuō)明 當(dāng)指針字符串Str為nil時(shí)將觸發(fā)異常
參考 <NULL>
例子 SpinEdit2.Value := StrLen(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function StrEnd(const Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串的結(jié)尾
說(shuō)明 當(dāng)指針字符串Str為nil時(shí)將觸發(fā)異常
參考 <NULL>
例子 Edit2.Text := StrEnd(PChar(Edit1.Text)) - SpinEdit1.Value;
━━━━━━━━━━━━━━━━━━━━━
首部 function StrMove(Dest: PChar; const Source: PChar; Count: Cardinal):
PChar; $[SysUtils.pas
功能 返回將指針字符串Source指定內(nèi)存數(shù)量Count復(fù)制覆蓋到指針字符串Dest中
說(shuō)明 Dest沒(méi)有分配資源將觸發(fā)異常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復(fù)制到指針字符串Dest中
說(shuō)明 Dest應(yīng)已經(jīng)分配足夠的空間非則將觸發(fā)異常
參考 <NULL>
例子
///////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復(fù)制到指針字符串Dest中的結(jié)尾
說(shuō)明 可以連接指針字符串
參考 <NULL>
例子
///////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指定長(zhǎng)度MaxLen復(fù)制到指針字符串Dest中
說(shuō)明 Dest應(yīng)已經(jīng)分配足夠的空間非則將觸發(fā)異常
參考 <NULL>
例子
///////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復(fù)制到指針字符串Dest中
說(shuō)明 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指定長(zhǎng)度MaxLen復(fù)制到指針字符串Dest中
說(shuō)明 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
說(shuō)明 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
說(shuō)明 [注意]MaxLen指定連接后的最大長(zhǎng)度不是指針字符串Source的長(zhǎng)度
參考 <NULL>
例子
///////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
功能 返回比較兩個(gè)指針字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě);[注意]返回第一個(gè)出現(xiàn)不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrComp(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function StrIComp(const Str1, Str2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個(gè)指針字符串
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě);[注意]返回第一個(gè)出現(xiàn)不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;
$[SysUtils.pas
功能 返回比較兩個(gè)指針字符串指定長(zhǎng)度
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě);Length(長(zhǎng)度);[注意]返回第一個(gè)出現(xiàn)不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrLComp(PChar(Edit1.Text), PChar(Edit2.Text),
SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
首部 function StrLIComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;
$[SysUtils.pas
功能 返回比較兩個(gè)指針字符串指定長(zhǎng)度
說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě);[注意]返回第一個(gè)出現(xiàn)不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrLIComp(PChar(Edit1.Text), PChar(Edit2.Text),
SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
首部 function StrScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr第一個(gè)出現(xiàn)的地址
說(shuō)明 沒(méi)有找到則返回空指針
posted on 2010-02-11 14:07
Ke 閱讀(1802)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
delphi