Delphi字符串函数大全.docx

上传人:b****4 文档编号:12278387 上传时间:2023-04-17 格式:DOCX 页数:60 大小:35.65KB
下载 相关 举报
Delphi字符串函数大全.docx_第1页
第1页 / 共60页
Delphi字符串函数大全.docx_第2页
第2页 / 共60页
Delphi字符串函数大全.docx_第3页
第3页 / 共60页
Delphi字符串函数大全.docx_第4页
第4页 / 共60页
Delphi字符串函数大全.docx_第5页
第5页 / 共60页
点击查看更多>>
下载资源
资源描述

Delphi字符串函数大全.docx

《Delphi字符串函数大全.docx》由会员分享,可在线阅读,更多相关《Delphi字符串函数大全.docx(60页珍藏版)》请在冰豆网上搜索。

Delphi字符串函数大全.docx

Delphi字符串函数大全

Delphi字符串函数大全

◇[DELPHI]字符串的过程和函数

Insert(obj,target,pos);//字符串target插入在pos的位置。

如插入结果大于target最大长度,多出字符将被截掉。

如Pos在255以外,会产生运行错。

例如,st:

='Brian',则Insert('OK',st,2)会使st变为'BrOKian'。

Delete(st,pos,Num);//从st串中的pos(整型)位置开始删去个数为Num(整型)个字符的子字串。

例如,st:

='Brian',则Delete(st,3,2)将变为Brn。

Str(value,st);//将数值value(整型或实型)转换成字符串放在st中。

例如,a=2.5E4时,则str(a:

10,st)将使st的值为'25000'。

Val(st,var,code);//把字符串表达式st转换为对应整型或实型数值,存放在var中。

St必须是一个表示数值的字符串,并符合数值常数的规则。

在转换过程中,如果没有检测出错误,变量code置为0,否则置为第一个出错字符的位置。

例如,st:

=25.4E3,x是一个实型变量,则val(st,x,code)将使X值为25400,code值为0。

Copy(st.pos.num);//返回st串中一个位置pos(整型)处开始的,含有num(整型)个字符的子串。

如果pos大于st字符串的长度,那就会返回一个空串,如果pos在255以外,会引起运行错误。

例如,st:

='Brian',则Copy(st,2,2)返回'ri'。

Concat(st1,st2,st3……,stn);//把所有自变量表示出的字符串按所给出的顺序连接起来,并返回连接后的值。

如果结果的长度255,将产生运行错误。

例如,st1:

='Brian',st2:

='',st3:

='Wilfred',则Concat(st1,st2,st3)返回'BrianWilfred'。

Length(st);//返回字符串表达式st的长度。

例如,st:

='Brian',则Length(st)返回值为5。

Pos(obj,target);//返回字符串obj在目标字符串target的第一次出现的位置,如果target没有匹配的串,Pos函数的返回值为0。

例如,target:

='BrianWilfred',则Pos('Wil',target)的返回值是7,Pos('hurbet',target)的返回值是0。

usesStrUtils

首部functionAnsiResemblesText(constAText,AOther:

string):

Boolean;$[StrUtils.pas

功能返回两个字符串是否相似

说明ANSI(AmericanNationalStandardsInstitute)美国国家标准协会;不区分大小写

参考functionStrUtils.SoundexProc;varStrUtils.AnsiResemblesProc

例子CheckBox1.Checked:

=AnsiResemblesText(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiContainsText(constAText,ASubText:

string):

Boolean;$[StrUtils.pas

功能返回字符串AText是否包含子串ASubText

说明不区分大小写

参考functionStrUtils.AnsiUppercase;functionStrUtils.AnsiPos

例子CheckBox1.Checked:

=AnsiContainsText(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiStartsText(constASubText,AText:

string):

Boolean;$[StrUtils.pas

功能返回字符串AText是否以子串ASubText开头

说明不区分大小写

参考functionWindows.CompareString

例子CheckBox1.Checked:

=AnsiStartsText(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiEndsText(constASubText,AText:

string):

Boolean;$[StrUtils.pas

功能返回字符串AText是否以子串ASubText结尾

说明不区分大小写

参考functionWindows.CompareString

例子CheckBox1.Checked:

=AnsiEndsText(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiReplaceText(constAText,AFromText,AToText:

string):

string;$[StrUtils.pas

功能返回字符串AText中用子串AFromText替换成子串AToText的结果

说明不区分大小写

参考functionSysUtils.StringReplace;typeSysUtils.TReplaceFlags

例子Edit4.Text:

=AnsiReplaceText(Edit1.Text,Edit2.Text,Edit3.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiMatchText(constAText:

string;constAValues:

arrayofstring):

Boolean;$[StrUtils.pas

功能返回字符串数组AValues中是否包含字符串AText

说明不区分大小写

参考functionStrUtils.AnsiIndexText

例子CheckBox1.Checked:

=AnsiMatchText(Edit1.Text,['a1','a2','a3','a4']);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiIndexText(constAText:

string;constAValues:

arrayofstring):

Integer;$[StrUtils.pas

功能返回字符串AText在字符串数组AValues中的位置

说明不区分大小写;如果不包含则返回-1

参考functionSysUtils.AnsiSameText

例子SpinEdit1.Value:

=AnsiIndexText(Edit1.Text,['a1','a2','a3','a4']);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiContainsStr(constAText,ASubText:

string):

Boolean;$[StrUtils.pas

功能返回字符串AText是否包含子串ASubText

说明区分大小写

参考functionStrUtils.AnsiPos

例子CheckBox1.Checked:

=AnsiContainsStr(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiStartsStr(constASubText,AText:

string):

Boolean;$[StrUtils.pas

功能返回字符串AText是否以子串ASubText开头

说明区分大小写

参考functionSysUtils.AnsiSameStr

例子CheckBox1.Checked:

=AnsiStartsStr(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiEndsStr(constASubText,AText:

string):

Boolean;$[StrUtils.pas

功能返回字符串AText是否以子串ASubText结尾

说明区分大小写

参考functionSysUtils.AnsiSameStr

例子CheckBox1.Checked:

=AnsiEndsStr(Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiReplaceStr(constAText,AFromText,AToText:

string):

string;$[StrUtils.pas

功能返回字符串AText中用子串AFromText替换成子串AToText的结果

说明区分大小写

参考functionSysUtils.StringReplace;typeSysUtils.TReplaceFlags

例子Edit4.Text:

=AnsiReplaceStr(Edit1.Text,Edit2.Text,Edit3.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiMatchStr(constAText:

string;constAValues:

arrayofstring):

Boolean;$[StrUtils.pas

功能返回字符串数组AValues中是否包含字符串AText

说明区分大小写

参考functionStrUtils.AnsiIndexStr

例子CheckBox1.Checked:

=AnsiMatchStr(Edit1.Text,['a1','a2','a3','a4']);

━━━━━━━━━━━━━━━━━━━━━

首部functionAnsiIndexStr(constAText:

string;constAValues:

arrayofstring):

Integer;$[StrUtils.pas

功能返回字符串AText在字符串数组AValues中的位置

说明区分大小写

参考functionSysUtils.AnsiSameStr

例子SpinEdit1.Value:

=AnsiIndexStr(Edit1.Text,['a1','a2','a3','a4']);

━━━━━━━━━━━━━━━━━━━━━

首部functionDupeString(constAText:

string;ACount:

Integer):

string;$[StrUtils.pas

功能返回字符串AText的ACount个复本

说明当ACount为0时返回''

参考functionSystem.SetLength

例子Edit3.Text:

=DupeString(Edit1.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionReverseString(constAText:

string):

string;$[StrUtils.pas

功能返回字符串AText的反序

说明ReverseString('1234')='4321'

参考functionSystem.SetLength

例子Edit3.Text:

=ReverseString(Edit1.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionStuffString(constAText:

string;AStart,ALength:

Cardinal;constASubText:

string):

string;$[StrUtils.pas

功能返回嵌套字符串

说明AStart:

嵌套开始位置;ALength:

嵌套长度;StuffString('abcd',2,0,'12')='a12bcd'

参考functionSystem.Copy

例子Edit3.Text:

=StuffString(Edit1.Text,SpinEdit1.Value,SpinEdit2.Value,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionRandomFrom(constAValues:

arrayofstring):

string;overload;$[StrUtils.pas

功能随机返回字符串数组AValues中的一个元素

说明之前建议执行Randomize

参考functionSystem.Random

例子Randomize;Edit3.Text:

=RandomFrom(['a1','a2','a3','a4']);

━━━━━━━━━━━━━━━━━━━━━

首部functionIfThen(AValue:

Boolean;constATrue:

string;AFalse:

string=''):

string;overload;$[StrUtils.pas

功能返回指定的逻辑字符串

说明IfThen(True,'是','否')='是';IfThen(False,'是','否')='否'

参考

例子Edit3.Text:

=IfThen(CheckBox1.Checked,Edit1.Text,Edit2.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionLeftStr(constAText:

string;constACount:

Integer):

string;$[StrUtils.pas

功能返回字符串AText左边的ACount个字符

说明LeftStr('123456',3)='123'

参考functionSystem.Copy

例子Edit3.Text:

=LeftStr(Edit1.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionRightStr(constAText:

string;constACount:

Integer):

string;$[StrUtils.pas

功能返回字符串AText右边的ACount个字符

说明RightStr('123456',3)='456'

参考functionSystem.Copy

例子Edit3.Text:

=RightStr(Edit1.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionMidStr(constAText:

string;constAStart,ACount:

Integer):

string;$[StrUtils.pas

功能返回字符串AText从AStart开始的ACount个字符

说明其实就是Copy

参考functionSystem.Copy

例子Edit3.Text:

=MidStr(Edit1.Text,SpinEdit1.Value,SpinEdit2.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionSearchBuf(Buf:

PChar;BufLen:

Integer;SelStart,SelLength:

Integer;SearchString:

String;Options:

TStringSearchOptions=[soDown]):

PChar;$[StrUtils.pas

功能返回第一个搜索到的指针位置

说明这函数常用于文本中搜索字符串

参考

例子

///////BeginSearchBuf

functionSearchEdit(EditControl:

TCustomEdit;constSearchString:

String;

SearchOptions:

TStringSearchOptions;FindFirst:

Boolean=False):

Boolean;

var

Buffer,P:

PChar;

Size:

Word;

begin

Result:

=False;

if(Length(SearchString)=0)thenExit;

Size:

=EditControl.GetTextLen;

if(Size=0)thenExit;

Buffer:

=StrAlloc(Size+1);

try

EditControl.GetTextBuf(Buffer,Size+1);

P:

=SearchBuf(Buffer,Size,EditControl.SelStart,EditControl.SelLength,

SearchString,SearchOptions);

ifP<>nilthenbegin

EditControl.SelStart:

=P-Buffer;

EditControl.SelLength:

=Length(SearchString);

Result:

=True;

end;

finally

StrDispose(Buffer);

end;

end;

procedureTForm1.Button1Click(Sender:

TObject);

var

SearchOptions:

TStringSearchOptions;

begin

SearchOptions:

=[];

ifCheckBox1.Checkedthen

Include(SearchOptions,soDown);

ifCheckBox2.Checkedthen

Include(SearchOptions,soMatchCase);

ifCheckBox3.Checkedthen

Include(SearchOptions,soWholeWord);

SearchEdit(Memo1,Edit1.Text,SearchOptions);

Memo1.SetFocus;

end;

///////EndSearchBuf

━━━━━━━━━━━━━━━━━━━━━

首部functionSoundex(constAText:

string;ALength:

TSoundexLength=4):

string;$[StrUtils.pas

功能返回探测字符串

说明根据探测法(Soundex)可以找到相进的字符串;http:

//www.nara.gov/genealogy/coding.html

参考

例子Edit2.Text:

=Soundex(Edit1.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionSoundexInt(constAText:

string;ALength:

TSoundexIntLength=4):

Integer;$[StrUtils.pas

功能返回探测整数

说明ALength的值越大解码准确率越高

参考

例子SpinEdit2.Value:

=SoundexInt(Edit1.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionDecodeSoundexInt(AValue:

Integer):

string;$[StrUtils.pas

功能返回探测整数的解码

说明DecodeSoundexInt(SoundexInt('hello'))相当于Soundex('hello')

参考

例子Edit2.Text:

=DecodeSoundexInt(SpinEdit2.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionSoundexWord(constAText:

string):

Word;$[StrUtils.pas

功能返回探测文字数值

说明没有参数ALength已经固定为4

参考

例子SpinEdit2.Value:

=SoundexWord(Edit1.Text);

━━━━━━━━━━━━━━━━━━━━━

首部functionDecodeSoundexWord(AValue:

Word):

string;$[StrUtils.pas

功能返回探测文字数值的解码

说明DecodeSoundexWord(SoundexWord('hello'))相当于Soundex('hello')

参考

例子Edit2.Text:

=DecodeSoundexWord(SpinEdit2.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionSoundexSimilar(constAText,AOther:

string;ALength:

TSoundexLength=4):

Boolean;$[StrUtils.pas

功能返回两个字符串的探测字符串是否相同

说明Result:

=Soundex(AText,ALength)=Soundex(AOther,ALength)

参考

例子CheckBox1.Checked:

=SoundexSimilar(Edit1.Text,Edit2.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部functionSoundexCompare(constAText,AOther:

string;ALength:

TSoundexLength=4):

Integer;$[StrUtils.pas

功能返回比较两个字符串的探测字符串的结果

说明Result:

=AnsiCompareStr(Soundex(AText,ALength),Soundex(AOther,ALength))

参考functionSysUtils.AnsiCompareStr

例子SpinEdit2.Value:

=SoundexCompare(Edit1.Text,Edit2.Text,SpinEdit1.Value);

━━━━━━━━━━━━━━━━━━━━━

首部

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1