首部 function QuotedStr(const S: string): string; $[SysUtils.pas
功能 返回字串S在pascal中的表現形式
說明 單引號中的一個單引號將轉成兩個
參考 procedure System.Insert
例子 Edit2.Text := QuotedStr(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiQuotedStr(const S: string; Quote: Char): string; $[SysUtils.pas
功能 返回字串S以字元Quote為引號的表現形式
說明 AnsiQuotedStr('hello"world', '@')='@hello"world@';AnsiQuotedStr('hello"world', '"')='"hello""world"'
參考 function SysUtils.AnsiStrScan
例子 Edit2.Text := AnsiQuotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
首部 function IfThen(AValue: Boolean; const ATrue: string; AFalse: string = ''): string; overload; $[StrUtils.pas
功能 返回指定的邏輯字串
說明 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個字元
說明 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 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 AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle = {$IFDEF LINUX} tlbsLF {$ENDIF} {$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}): string; $[SysUtils.pas
功能 返回將給定字串的行分隔字元調整為CR/LF序列
說明 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
━━━━━━━━━━━━━━━━━━━━━
首部 function Format(const Format: string; const Args: array of const): string; $[SysUtils.pas
功能 返回按指定方式格式化一個常數陣列的字元形式
說明 這個函數是我在Delphi中用得最多的函數,現在就列舉幾個例子給你個直觀的理解
"%" [索引 ":"] ["-"] [寬度] ["." 摘要] 類型
Format('x=%d', [12]); //'x=12' //最普通
Format('x=%3d', [12]); //'x= 12' //指定寬度
Format('x=%f', [12.0]); //'x=12.00' //浮點數
Format('x=%.3f', [12.0]); //'x=12.000' //指定小數
Format('x=%.*f', [5, 12.0]); //'x=12.00000' //動態配置
Format('x=%.5d', [12]); //'x=00012' //前面補充0
Format('x=%.5x', [12]); //'x=0000C' //十六進位
Format('x=%1:d%0:d', [12, 13]); //'x=1312' //使用索引
Format('x=%p', [nil]); //'x=00000000' //指標
Format('x=%1.1e', [12.0]); //'x=1.2E+001' //科學記號標記法
Format('x=%%', []); //'x=%' //得到"%"
S := Format('%s%d', [S, I]); //S := S + StrToInt(I); //連接字串
參考 proceduer SysUtils.FmtStr
例子 Edit1.Text := Format(Edit2.Text, [StrToFloatDef(Edit.3.Text, 0)]);