1、pos(...)函数
原型说明:function Pos(Substr: string; S: string): Integer;
该函数在字符串S中查找Substr,并且返回Substr第一个字符在S中的序号Index值,如果没有找到字符串SubStr则返回0,pos()函数对大小写敏感。
例一、BUTTON4查找edit7中的字符串是否在EDIT6中的字符串中。若在则显示其在原字符串中的位置。
procedure TForm1.Button4Click(Sender: TObject);
var
s,substr:string;
i:integer;
begin
substr:=edit7.Text;
s:=edit6.Text ;
if pos(substr,s)=0 then
showmessage('没有找到该子串')
else
showmessage('找到了该字符串,从原字符串第'+IntToStr(pos(substr,s))+'位开始');
end;
该代码通过DELPHI6编译实现。
2、StrToInt(),StrToIntDef()函数:
StrToInt()函数原型说明为:function StrToInt(const S: string): Integer;
StrToIntDef()函数原型说明为:function StrToIntDef(const S: string; Default: Integer): Integer;
这两个函数将代表整数的字符串S(十进制或者十六进制)转换成相应的整数,如果S代表一个合法的整数,则返回其对应的整数值,若S代表一个非法的整数,对于StrToIntDef()函数则返回参数Default的值;而函数StrToInt()则引发错误。
例二、将EDIT1里的内容转换成整数并在EDIT2内显示,若EDIT1输入的为非法数据则在EDIT2内输入1000。
procedure TForm1.Button1Click(Sender: TObject);
var
Number: Integer;
begin
Number := StrToIntDef(Edit1.Text, 1000);
Edit2.Text := IntToStr(Number);
end;
例二、判断字符串是否可以转换为整数
function IsIntStr(const S: string): boolean;
begin
Result:=StrToIntDef(S,0)=StrToIntDef(S,1);
end
3、Concat()函数:连接两个或者更多字符串为一个字符串
函数原型说明:function Concat(s1 [, s2,..., sn]: string): string;返回连接后的字符串,该函数功能与'+'一样。
4、Copy()函数:用来截取字符串中的的一段;
原型说明:function Copy(S; Index, Count: Integer): string;//从字符创S的Index处开始截取Count个字符返回
function Copy(S; Index, Count: Integer): array;//与字符串操作相似,但是只能作为过程或函数调用时的参数。
5、Delete()过程
原型说明:procedure Delete(var S: string; Index, Count:Integer);//讲字符串S从Index处开始删除Count个字符。
6、Insert()过程
原型说明:
procedure Insert(Source: string; var S: string; Index: Integer);//将字符串Source插入到S字符串index处。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。