Delphi6函数大全

首部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; 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)可以找到相进的字符串;http://www.nara.gov/genealogy/coding.html参考例子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('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('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;]
chm 文件大小:29.75KB