Delphi的StringReplace 字符串替换函数

合集下载

Delphi常用字符串函数

Delphi常用字符串函数
b = left(code,3) = 123
c = substring(code,4,2) = 45
d = substring(code,6,3) = 678
e = b+'-'+c+'-'+e = 123-45-678
f = replace(code,a,e) = 123-45-6789
配合下边的来看,应该能明白了
此函数不能用于TEXT 和IMAGE 数据类型。
2、PATINDEX()
返回字符串中某个指定的子串出现的开始位置。
PATINDEX (<’%substring _expression%’>, <column_ name>)其中子串表达式前后必须有百分号“%”否则返回值为0。
与CHARINDEX 函数不同的是,PATINDEX函数的子串中可以使用通配符,且此函数可用于CHAR、 VARCHAR 和TEXT 数据类型。
南山古桃 NSGTao 网址:/nsgtao
2、REPLICATE()
返回一个重复character_expression 指定次数的字符串。
REPLICATE (character_expression integer_expression) 如果integer_expression 值为负值,则返回NULL 。
4、SPACE()
返回一个有指定长度的空白字符串。
SPACE (<integer_expression>) 如果integer_expression 值为负值,则返回NULL 。
5、STUFF()
用另一子串替换字符串指定位置、长度的子串。

Delphi字符串函数

Delphi字符串函数
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiMatchStr(const AText: string; const AValues: array of
string): Boolean; $[StrUtils.pas
功能 返回字符串数组AValues中是否包含字符串AText
参考 function StrUtils.SoundexProc; var StrUtils.AnsiResemblesProc
例子 CheckBox1.Checked := AnsiResemblesText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
参考 function StrUtils.AnsiUppercase; function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━
首部 function AnsiReplaceText(const AText, AFromText, AToText: string):
strinபைடு நூலகம்; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替换成子串AToText的结果
首部 function AnsiStartsStr(const ASubText, AText: string): Boolean;
$[StrUtils.pas
功能 返回字符串AText是否以子串ASubText开头

Delphi5常用函数说明

Delphi5常用函数说明

⏹字符处理⏹数值与字符串转换⏹数值处理⏹内存分配和释放⏹文件管理一、字符处理⏹AdjustLineBreaks function格式字符串中的换行符为回车/换行符(CR/LF)。

声明:f unction AdjustLineBreaks(const S: string): string;参数:s -- 需要格式化的字符串;返回:s格式化后的字符串⏹AnsiCompareStr function根据当前Windows地方版本比较两个字段串大小(大小写区分)。

声明:f unction AnsiCompareStr(const S1, S2: string): Integer;参数:S1,S2 -- 需要比较大小的两个字符串;返回:> 0 -- 当S1 > S2时;< 0 -- 当S1 < S2时;= 0 -- 当S1 = S2时。

⏹AnsiCompareText function根据当前Windows地方版本比较两个字段串大小(大小写不区分)。

声明:f unction AnsiCompareText(const S1, S2: string): Integer;参数:S1,S2 -- 需要比较大小的两个字符串;返回:> 0 -- 当S1 > S2时;< 0 -- 当S1 < S2时;= 0 -- 当S1 = S2时。

⏹AnsiExtractQuotedStr function转换带引号的字符串为不带引号的字符串,引号可自定义为任何字符,同时去掉引号外的字符。

声明:f unction AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;参数:S rc -- 源字符串;Quote -- 引号字符;返回:S rc去掉引号后的字符串,同时去掉引号外的字符。

⏹AnsiLowerCase function返回一个字符串对应的小写字符串。

Delphi 字符串函数大全

Delphi 字符串函数大全

【字符串函数大全】首部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 pareString例子CheckBox1.Checked := AnsiStartsText(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiEndsText(const ASubText, AText: string): Boolean;$[StrUtils.pas功能返回字符串AText是否以子串ASubText结尾说明不区分大小写参考function pareString例子CheckBox1.Checked := AnsiEndsText(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiReplaceText(const AText, AFromText, AToText: string): string; $[StrUtils.pas功能返回字符串AText中用子串AFrom Text替换成子串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.AnsiSam eText例子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 AS ubText, AText: string): Boolean; $[StrUtils.pas功能返回字符串AText是否以子串ASubText开头说明区分大小写参考function SysUtils.AnsiSam eStr例子CheckBox1.Checked := AnsiStartsStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiEndsStr(const ASubText, AText: string): Boolean; $[StrUtils.pas功能返回字符串AText是否以子串ASubText结尾说明区分大小写参考function SysUtils.AnsiSam eStr例子CheckBox1.Checked := AnsiEndsStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiReplaceStr(const AText, AFromText, AToText: string): string; $[StrUtils.pas功能返回字符串AText中用子串AFrom Text替换成子串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.AnsiSam eStr例子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 := Random From(['a1', 'a2', 'a3', 'a4']);━━━━━━━━━━━━━━━━━━━━━首部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 SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String; Options: TStringSearchOptions = [soDown]): PChar; $[StrUtils.pas功能返回第一个搜索到的指针位置说明这函数常用于文本中搜索字符串参考<NULL>例子///////Begin SearchBuffunction SearchEdit(EditControl: TCustom Edit; const SearchString: String; SearchOptions: TStringSearchOptions; FindFirst: Boolean = False): Boolean; varBuffer, P: PChar;Size: Word;beginResult := False;if (Length(SearchString) = 0) then Exit;Size := EditControl.GetTextLen;if (Size = 0) then Exit;Buffer := StrAlloc(Size + 1);tryEditControl.GetTextBuf(Buffer, Size + 1);P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength, SearchString, SearchOptions);if P <> nil then beginEditControl.SelStart := P - Buffer;EditControl.SelLength := Length(SearchString);Result := True;end;finallyStrDispose(Buffer);end;end;procedure TForm1.Button1Click(Sender: TObject);varSearchOptions: TStringSearchOptions;beginSearchOptions := [];if CheckBox1.Checked thenInclude(SearchOptions, soDown);if CheckBox2.Checked thenInclude(SearchOptions, soMatchCase);if CheckBox3.Checked thenInclude(SearchOptions, soWholeWord);SearchEdit(Mem o1, Edit1.Text, SearchOptions);Mem o1.SetFocus;end;///////End SearchBuf━━━━━━━━━━━━━━━━━━━━━首部function Soundex(const AText: string; ALength: TSoundexLength = 4): string; $[StrUtils.pas功能返回探测字符串说明根据探测法(Soundex)可以找到相进的字符串;/genealogy/coding.ht m l参考<NULL>例子Edit2.Text := Soundex(Edit1.Text, SpinEdit1.Value);━━━━━━━━━━━━━━━━━━━━━首部function SoundexInt(const AText: string; ALength: TSoundexIntLength =4): Integer; $[StrUtils.pas功能返回探测整数说明ALength的值越大解码准确率越高参考<NULL>例子SpinEdit2.Value := SoundexInt(Edit1.Text, SpinEdit1.Value);━━━━━━━━━━━━━━━━━━━━━首部function DecodeSoundexInt(AValue: Integer): string; $[StrUtils.pas 功能返回探测整数的解码说明DecodeSoundexInt(SoundexInt('hello')) 相当于Soundex('hello')参考<NULL>例子Edit2.Text := DecodeSoundexInt(SpinEdit2.Value);━━━━━━━━━━━━━━━━━━━━━首部function SoundexWord(const AText: string): Word; $[StrUtils.pas功能返回探测文字数值说明没有参数ALength已经固定为4参考<NULL>例子SpinEdit2.Value := SoundexWord(Edit1.Text);━━━━━━━━━━━━━━━━━━━━━首部function DecodeSoundexWord(AValue: Word): string; $[StrUtils.pas 功能返回探测文字数值的解码说明DecodeSoundexWord(SoundexWord('hello')) 相当于Soundex('hello') 参考<NULL>例子Edit2.Text := DecodeSoundexWord(SpinEdit2.Value);━━━━━━━━━━━━━━━━━━━━━首部function SoundexSimilar(const AText, AOther: string; ALength:TSoundexLength = 4): Boolean; $[StrUtils.pas功能返回两个字符串的探测字符串是否相同说明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功能返回比较两个字符串的探测字符串的结果说明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: TCom pareTextProc = SoundexProc;]━━━━━━━━━━━━━━━━━━━━━首部function NewStr(const S: string): PString; deprecated; $[SysUtils.pas 功能返回一个新的字符串指针地址说明字符串S为空时返回NullStr参考procedure System.New例子////////Begin NewStr,DisposeStrprocedure TForm1.Button1Click(Sender: TObject);varP: PString;beginP := 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 AssignStrprocedure TForm1.Button1Click(Sender: TObject);varP: PString;beginP := 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已经不建议使用参考<NULL>例子////////Begin AppendStrprocedure TForm1.Button1Click(Sender: TObject);varS: string;beginS := 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<S2返回值<0;当S1=S2返回值=0;区分大小写参考<NULL>例子SpinEdit1.Value := CompareStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function CompareMem(P1, P2: Pointer; Length: Integer): Boolean;assem bler; $[SysUtils.pas功能返回比较两个内存指针说明Com pareMem(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功能返回比较两个字符串说明不区分大小写参考<NULL>例子SpinEdit1.Value := Compa reText(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function SameText(const S1, S2: string): Boolean; $[SysUtils.pas功能返回两个字符串是否相等说明不区分大小写参考<NULL>例子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<S2返回值<0;当S1=S2返回值=0;区分大小写参考function pareString例子SpinEdit1.Value := AnsiCompareStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiSameStr(const S1, S2: string): Boolean; $[SysUtils.pas功能返回两个字符串是否相等说明区分大小写参考function SysUtils.AnsiCompareStr例子CheckBox1.Checked := AnsiSameStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiCompareText(const S1, S2: string): Integer; $[SysUtils.pas 功能反回比较两个字符串说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;不区分大小写参考function pareString例子SpinEdit1.Value := AnsiCompareText(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiSameText(const S1, S2: string): Boolean; $[SysUtils.pas功能返回两个字符串是否相等说明不区分大小写参考function SysUtils.AnsiCompareText例子CheckBox1.Checked := AnsiSameText(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrComp(S1, S2: PChar): Integer; $[SysUtils.pas功能返回比较两个指针字符串说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;区分大小写参考function pareString例子SpinEdit1.Value := AnsiStrComp(PChar(Edit1.Text), PChar(Edit2.Text))━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrIComp(S1, S2: PChar): Integer; $[SysUtils.pas功能返回比较两个指针字符串说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;不区分大小写;Ignore(忽略)参考function pareString例子SpinEdit1.Value := AnsiStrIComp(PChar(Edit1.Text), PChar(Edit2.Text)) ━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer;$[SysUtils.pas功能返回比较两个指针字符串指定长度说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;区分大小写;Length(长度)参考function pareString例子SpinEdit1.Value := AnsiStrLComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer;$[SysUtils.pas功能返回比较两个指针字符串指定长度说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;不区分大小写参考function pareString例子SpinEdit1.Value := AnsiStrLIComp(P Char(Edit1.Text), PChar(Edit2.Text),SpinEdit2.Value)━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrLower(Str: PChar): PChar; $[SysUtils.pas功能返回指针字符串小写形式说明非大写字符不处理参考function Windows.CharLower例子Edit2.Text := AnsiStrLower(PChar(Edit1.Text));━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrUpper(Str: PChar): PChar; $[SysUtils.pas功能返回指针字符串大写形式说明非小写字符不处理参考function Windows.CharUpper例子Edit2.Text := AnsiStrUpper(PChar(Edit1.Text));━━━━━━━━━━━━━━━━━━━━━首部function AnsiLastChar(const S: string): PChar; $[SysUtils.pas 功能返回字符串S的最后一个指针字符说明当字符串S为空串则返回空指针参考function SysUtils.ByteType例子Edit2.Text := AnsiLastChar(Edit1.Text);━━━━━━━━━━━━━━━━━━━━━首部function AnsiStrLastChar(P: PChar): PChar; $[SysUtils.pas功能返回指针字符串P的最后一个指针字符说明当字符串P为空空指针则返回空指针参考function SysUtils.ByteType例子Edit2.Text := AnsiLastChar(PChar(Edit1.Text));━━━━━━━━━━━━━━━━━━━━━首部function WideUpperCase(const S: WideString): WideString; $[SysUtils.pas功能返回双字节字符串的大写形式说明WideChar双字节字符参考function Windows.CharUpperBuffW例子Edit2.Text := WideUpperCase(Edit1.Text);━━━━━━━━━━━━━━━━━━━━━首部function WideLowerCase(const S: WideString): WideString; $[SysUtils.pas功能返回双字节字符串的小写形式说明我怎么就测试不出来呢参考function Windows.CharLowerBuffW例子Edit2.Text := WideLowerCase(Edit1.Text);━━━━━━━━━━━━━━━━━━━━━首部function WideCompareStr(const S1, S2: WideString): Integer;$[SysUtils.pas功能返回比较两个双字节字符串说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;区分大小写参考function pareStringW例子SpinEdit1.Value := WideCompareStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function WideSameStr(const S1, S2: WideString): Boolean; $[SysUtils.pas 功能返回两个双字节字符串是否相同说明区分大小写参考function SysUtils.WideCompareStr例子CheckBox1.Checked := WideSameStr(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function WideCompareText(const S1, S2: WideString): Integer;$[SysUtils.pas功能返回比较两个双字节字符串说明当S1>S2返回值>0;当S1<S2返回值<0;当S1=S2返回值=0;不区分大小写参考function pareStringW例子SpinEdit1.Value := WideCompareText(Edit1.Text, Edit2.Text);━━━━━━━━━━━━━━━━━━━━━首部function WideSameText(const S1, S2: WideString): Boolean; $[SysUtils.pas功能返回两个双字节字符串是否相同说明不区分大小写参考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左右不可见字符说明小于#32的字符看作不可见字符参考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左边不可见字符说明小于#32的字符看作不可见字符参考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右边不可见字符说明小于#32的字符看作不可见字符参考function System.Copy例子Edit2.Text := TrimRight(Edit1.Text);━━━━━━━━━━━━━━━━━━━━━首部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 AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string; $[SysUtils.pas功能返回以字符Quote为引号的表现形式原形说明表现形式非法时Src不变否则为空参考function SysUtils.AnsiStrScan例子///////Begin AnsiExtractQuotedStrprocedure TForm1.Button1Click(Sender: TObject);varP: PChar;beginP := PChar(Edit1.Text);Edit2.Text := AnsiExtractQuotedStr(P, '"');Edit3.Text := P;end;///////End AnsiExtractQuotedStr━━━━━━━━━━━━━━━━━━━━━首部function AnsiDequotedStr(const S: string; AQuote: Char): string;$[SysUtils.pas功能返回以字符AQuote为引号的表现形式原形说明表现形式非法时则返回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功能返回将给定字符串的行分隔符调整为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例子<NULL>━━━━━━━━━━━━━━━━━━━━━首部function IsValidIdent(const Ident: string): Boolean; $[SysUtils.pas功能返回字符串Ident是否是正确的标识符说明标识符::字母|下划线[字母|下划线|数字]...参考<NULL>例子CheckBox1.Checked := IsValidIdent(Edit1.Text);━━━━━━━━━━━━━━━━━━━━━首部function IntToStr(Value: Integer): string; overload; $[SysUtils.pas首部function IntToStr(Value: Int64): string; overload; $[SysUtils.pas功能返回整数Value转换成字符串说明Form at('%d', [Value])参考function SysUtils.Fm tStr例子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.Fm tStr例子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 := StrToInt Def(Edit1.Text, 0);━━━━━━━━━━━━━━━━━━━━━首部function TryStrToInt(const S: string; out Value: Integer): Boolean; $[SysUtils.pas功能返回字符串S转换成整数Value是否成功说明字符串非整数表达时返回False并且Value将输出为0参考procedure System.Val例子///////Begin TryStrToIntprocedure TForm1.Button1Click(Sender: TObject);varI: Integer;beginCheckBox1.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 TryStrToInt64procedure TForm1.Button1Click(Sender: TObject);varI: Int64;beginCheckBox1.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.AnsiSam eText;var SysUtils.TrueBoolStrs;var SysUtils.FalseBoolStrs例子///////Begin TryStrToBoolprocedure TForm1.Button1Click(Sender: TObject);varB: Boolean;beginSetLength(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 TryStrToBoolfunction TryStrToBool(const S: string; out Value: Boolean): Boolean;function Com pareWith(const aArray: array of string): Boolean;varI: Integer;beginResult := False;for I := Low(aArray) to High(aArray) doif AnsiSam eText(S, aArray[I]) thenbeginResult := True;Break;end;end;varLResult: Extended;beginResult := TryStrToFloat(S, LResult);if Result thenValue := LResult <> 0elsebeginResult := True; //修正处VerifyBoolStrArray;if Com pareWith(TrueBoolStrs) then Value := Trueelse if Com pareWith(FalseBoolStrs) then Value := FalseelseResult := 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.Fm tStr;function SysUtils.FindStringResource例子<NULL>;━━━━━━━━━━━━━━━━━━━━━首部function StrLen(const Str: PChar): Cardinal; $[SysUtils.pas功能返回指针字符串的长度说明当指针字符串Str为nil时将触发异常参考<NULL>例子SpinEdit2.Value := StrLen(PChar(Edit1.Text));━━━━━━━━━━━━━━━━━━━━━首部function StrEnd(const Str: PChar): PChar; $[SysUtils.pas功能返回指针字符串的结尾说明当指针字符串Str为nil时将触发异常参考<NULL>例子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 StrMoveprocedure TForm1.Button1Click(Sender: TObject);varvBuffer: PChar;beginvBuffer := '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应已经分配足够的空间非则将触发异常参考<NULL>例子///////Begin StrCopyprocedure TForm1.Button1Click(Sender: TObject);varvBuffer: PChar;beginGetMem(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中的结尾说明可以连接指针字符串参考<NULL>例子///////Begin StrECopyprocedure TForm1.Button1Click(Sender: TObject);varvBuffer: array[0..255] of Char;beginStrECopy(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应已经分配足够的空间非则将触发异常参考<NULL>例子///////Begin StrLCopyprocedure TForm1.Button1Click(Sender: TObject);varvBuffer: array[0..255] of Char;beginStrLCopy(vBuffer, PChar(Edit1.Text), SpinEdit1.Value);Edit2.Text := vBuffer;end;///////End StrLCopy━━━━━━━━━━━━━━━━━━━━━首部function StrPCopy(Dest: PChar; const Source: string): PChar; $[SysUtils.pas功能返回将指针字符串Source复制到指针字符串Dest中说明StrLCopy(Dest, PChar(Source), Length(Source))参考function SysUtils.StrLCopy例子///////Begin StrPCopyprocedure TForm1.Button1Click(Sender: TObject);varvBuffer: array[0..255] of Char;beginStrPCopy(vBuffer, PChar(Edit1.Text));Edit2.Text := vBuffer;。

DelphiString常用字串符处理函数

DelphiString常用字串符处理函数

说明旧写法(Windows 平台)由1开始新写法(跨所有平台)由0开始插⼊字串Insert('str', Str, 1);Str := Str.Insert(0, 'str');删除字串Delete(Str, 1, 1);Str := Str.Remove(0);Str := Str.Remove(0, 1);复制字串Str := Copy(Str, 1, 2);Str := Str.Substring(0, 2);转成⼤写UpperCase(Str);Str := Str.ToUpper;转成⼩写LowerCase(Str);Str := Str.ToLower;重复字符StringOfChar('-', 15);Str := String.Cretae('-', 15);找⼦字符Pos('ABC123', Str);i := Str.IndexOf('ABC123');是这些字CharInSet(Str[1], [' ',#13]);Str.Chars[0].IsInArray([' ',#13]);制表 龟⼭阿卍DelphiString 常⽤字串符处理函数 Delphi 在⾯对跨平台开发,程序语⾔也改进不少,不过有些改进,让原本 Delphi 开发者有些不适应,最显注的就是字串处理函数了,原本Pascal 语⾔字串起始由 1 开始,⼏乎是它的经典了,新版本字串由 0 开始,这个改变,让很多⼈不适应,也多有抱怨,虽然 Delphi 尽量保有相容性,但如果要写出⼀码,跨所有平台,还是建议全部采⽤新的写法(由0开始),才是⼀劳永逸的做法,下⾯就整理常⽤字串处理函数新旧对照表。

Delphi String 常⽤字串符处理函数:先整理这些,有空再慢慢整理其它的。

可参考官⽅⽂件:。

字符串的replace函数的用法

字符串的replace函数的用法

字符串的replace函数的用法字符串的replace函数是一种非常常用的字符串操作函数,它可以用来替换字符串中的某些字符或字符串。

在本文中,我们将详细介绍replace函数的用法和一些注意事项。

replace函数的基本用法非常简单,它的语法如下:```str.replace(old, new[, count])```其中,str是要进行替换操作的字符串,old是要被替换的字符或字符串,new是替换后的字符或字符串,count是可选参数,表示最多替换的次数。

下面是一个简单的例子,演示了如何使用replace函数将字符串中的某些字符替换为其他字符:```str = "hello world"new_str = str.replace("o", "0")print(new_str) # 输出:hell0 w0rld```在上面的例子中,我们将字符串中的所有字母o替换为数字0。

除了替换单个字符外,replace函数还可以替换多个字符或字符串。

例如,我们可以将字符串中的所有空格替换为下划线:```str = "hello world"new_str = str.replace(" ", "_")print(new_str) # 输出:hello_world```需要注意的是,replace函数是不会修改原始字符串的,而是返回一个新的字符串。

因此,在使用replace函数时,需要将替换后的字符串赋值给一个新的变量。

replace函数还有一个可选参数count,它表示最多替换的次数。

例如,我们可以将字符串中的前两个字母o替换为数字0:```str = "hello world"new_str = str.replace("o", "0", 2)print(new_str) # 输出:hell0 w0rld```需要注意的是,如果count的值大于替换的次数,那么replace函数会将所有匹配的字符都替换掉。

delphi string用法 -回复

delphi string用法 -回复

delphi string用法-回复【Delphi String用法】一步一步回答Delphi语言是一种强大的编程语言,广泛用于Windows平台的开发。

在Delphi中,String类型是最常用的数据类型之一,用于处理文本和字符数据。

本文将逐步介绍Delphi String的用法,包括创建、操作和处理String 类型的变量。

一、创建String类型变量在Delphi中,使用String关键字声明一个String类型的变量。

可以使用以下语法声明String变量:varmyString: String;上述代码声明了一个名为myString的String类型变量。

二、赋值String变量可以使用多种方式为String变量赋值。

下面是几种常见的方法:1. 使用赋值运算符":"直接赋值给String变量:myString := 'Hello, World!';2. 通过输入和输出语句从用户那里获取String类型的输入:Readln(myString); 接收用户输入并赋值给myStringWriteLn(myString); 将myString的内容输出到控制台3. 通过函数返回值给String变量赋值:function GetGreeting: String;beginResult := 'Hello, World!';end;myString := GetGreeting;三、String类型的操作Delphi提供了一些内置的函数和过程,用于操作和处理String类型的变量。

以下是一些常见的操作:1. 字符串拼接:使用"+"运算符可以将两个字符串连接起来,生成一个新的字符串。

示例代码如下:varstr1, str2, strResult: String;beginstr1 := 'Hello, ';str2 := 'World!';strResult := str1 + str2; 拼接字符串ShowMessage(strResult); 显示结果end;2. 获取字符串长度:使用Length函数可以获得字符串的长度,即字符的数量。

Delphi常用函数和过程

Delphi常用函数和过程

8.1 数据类型转化类本节所列函数和过程一般都定义在System 或者SysUtils 单元。

8.1.1 数值和字符串的相互转化procedure Str(X [: Width [: Decimals ]]; var S);将数值X 按照一定格式转化为字符串S。

Width 指定S 的总长度,如果X 是实数,Decimals 指定小数点后的位数。

如:varS: String;beginStr(12.2:6:2,S); {S=’ 12.20’}end;procedure Val(S; var V; var Code: Integer);将字符串S 转化为数值V。

如果不能转化,则Code 返回第一个非法字符的位置。

如:varV,Code: Integer;beginVal(’12.00’, V, Code); {没能成功转化,Code返回’.’的位置3}end;8.1.2 整数和字符串的相互转化function IntToStr(Value: Integer): string; overload;function IntToStr(Value: Int64): string; overload;第一个用于32Bit 整数的转化,第二个用于64Bit 整数的转化。

因为Cardinal、Longword 等和Integer 是兼容的(即是说一个Integer 变量总是可以无损失地存储一个Cardinal 或者Longword 变量的值,因为Integer 的取值范围完全包含了它们的取值范围)。

function StrToInt(const S: string): Integer;function StrToInt64(const S: string): Int64;将一个字符串转化为整数。

如果S 包含非数字字符(如“ 1A”、“ 1.2”),则运行时产生异常。

但是S 也可以是十六进制表示方法,如“ $A”,那么会返回十进制数10。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档