Pascal中的常用字符串函数
- 格式:doc
- 大小:37.50 KB
- 文档页数:4
一、数学函数:Inc(i)使I:=I+1;Inc(I,b)使I:=I+b;Abs(x)求x的绝对值例:abs(-3)=3Chr(x)求编号x对应的字符。
例:Chr(65)=’A’chr(97)=’a’chr(48)=’0’Ord(x)求字符x对应的编号。
例:ord(‘A’)=65ord(‘a’)=97另外:ord(false)=0o rd(true)=1Sqr(x)求x的平方。
例:sqr(4)=16Sqrt(x)求x的开方.例:sqrt(16)=4round(x)求x的四舍五入例:round(4.5)=5trunc(x)求x的整数部分例:trunc(5.6)=5结果是integer型int(x)求x的整数部分例int(5.6)=5.0结果是real型frac(x)求x的小数部分例frac(5.6)=0.6pred(x)求x的前导pred(‘b’)=’a’pred(5)=4pred(true)=falsesucc(x)求x的后继succ(‘b’)=’c’succ(5)=6succ(false)=trueodd(x)判断x是否为奇数。
如果是值为true,反之值为false.Odd(2)=false od d(5)=truepower(a,n)求a的n次方power(2,3)=8exp(b*ln(a))a的b次方random取0~1之间的随机数(不能取到1)randomize随机数的种子函数,在每次设置随机数时都要把这个函数放在最前面.Fillchar(a,size(a),0)数组初始化,即把数组a的值全部置为0SHR:x SHR n把x换成二进制后向右移n位,相当于把x除以2na shr n等价于a div(2^n)SHL:x SHL n把x换成二进制后向左移n位,相当于把x乘以2n二、字符串函数1.连接运算concat(s1,s2,s3…sn)相当于s1+s2+s3+…+sn.例:concat(‘11’,’aa’)=’11aa’;2.求子串。
Pascal常用函数PASCAL内自带的函数,通常可以直接调用,特殊的需要调用数据库,如:used math一、标准函数二、数学函数与过程三、字符类型函数四、字符串函数与过程五、布尔类型函数六、math单元的函数与过程一、标准函数标准函数。
Turbo Pascal语言提供了自变量为整型量的标准函数有顺序函数算术函数和转换函数等。
标准函数是Turbo Pascal语言预先定义的,它们实际上是能完成特定功能的称步子程序的程序段。
每个标准函数都用一个标识符来标识,每个标准函数都能完成一个特定的功能,在程序中可以直接调用它们。
Turbo Pascal语言中某些标准函数与数学中的函数有相似之处。
1、整数类型函数整型是顺序类型,即所有的整型数都是按一定的顺序排列的。
如3的后序数是4,350的后序数是351。
以后介绍的布尔型、字符型、枚举类型和子界类型等都是顺序类型。
顺序函数可以对顺序类型数据进行操作,但要注意它们自变量的取值范围。
①前趋函数:Pred(x)函数值为x-l,例如:Pred (6)=5 Pred (-21)=-22②后继函数:Succ (x)函数值为x+l,例如:Succ (l5)=16 Succ (-114)= -113③绝对值函数:Abs (x)函数值为|X|,例如:Abs (-119)=119 Abs (101)=101④平方函数:Sqr (x)函数值为X*X,例如:Sqr (-5)=25 Sqr (l0)= 100以上四个函数的结果仍是整型数。
⑤奇函数:Odd (x),函数的结果为布尔型。
当X为奇数时,函数值为true;当X为偶数时,函数值为false,例如:Odd (13)= True Odd (16)= False⑥字符函数:Chr (X),函数值是序号的ASCII字符,属字符型,例如:Chr (65)=‟A‟ Chr (66)=‟B‟2、实数类型函数在下列算术函数中,X可以是实型或整型数的表达式。
字符串〖语法分析〗字符串用于存放整批的字符数据。
通常编程中使用字符串存放字符化了的数字数据。
如高精度运算时存放操作数和运算结果。
字符串可以看作是特殊的字符串数组来处理。
当然,它也有自已的特点。
下面是字符串定义的格式:var s:string; s1:string[15]; s[1] s[2] … s[255] s[0] ord(s[0]) 字符串定义时,如不指定长度,则按该类型的最大长度(255个字符)分配空间,使用时最大可用长度为255个;如果在中括号中给出一个具体的值(1—255之间),则按这个值的大小分配空间。
使用时,最大的可用长度即为该值。
1、字符串的输入、输出:字符串类型既可按数组方式输入、输出,也可直接输入、输出:readln(s);wr iteln(s);多个字符串输入时以回车作为数据间的分隔符;每个readln语句只能读入一个字符串。
2、有关字符串的操作:Const s:string[26]=’abcdefghijklmnopqrstuvwxyz’;Var t:string[26];I:integer;Begint:=’ ‘; {共26个空格}For I:=1 to 26 do beginT[I]:=s[27-I];End;Writeln(s);Writeln(t);End.[例6、4]找出所有的四位回文数:(回文数就是一个数从左往右读与从右往左读都是同一个数)var s:string[4];n:integer;beginfor n:=1000 to 9999 do beginstr(n,s);if (s[1]=s[4]) and (s[2]=s[3]) then write(n:6);end;end.或者用如下程序:var n:integer;s,t:string;beginfor n:=10 to 99 do beginstr(n,s);t:=s+s[2]+s[1];write(s:6);end;end.上述两个程序,哪个快,哪个慢?练习题:1、读入一串字符,以句号结束,然后让其倒序输出。
Pascal语言函数集(含Delphi控件属性) abort函数引起放弃的意外处理abs函数绝对值函数addexitproc函数将一过程添加到运行时库的结束过程表中addr函数返回指定对象的地址adjustlinebreaks函数将给定字符串的行分隔符调整为cr/lf序列align属性使控件位于窗口某部分alignment属性控件标签的文字位置allocmem函数在堆栈上分配给定大小的块allowgrayed属性允许一个灰度选择ansicomparestr函数比较字符串(区分大小写)ansicomparetext函数比较字符串(不区分大小写)ansilowercase函数将字符转换为小写ansiuppercase函数将字符转换为大写append函数以附加的方式打开已有的文件arctan函数余切函数assignfile函数给文件变量赋一外部文件名assigned函数测试函数或过程变量是否为空autosize属性自动控制标签的大小backgrounddi2001.jpg属性背景色beginthread函数以适当的方式建立用于内存管理的线程bevelinner属性控件方框的内框方式bevelouter属性控件方框的外框方式bevelwidth属性控件方框的外框宽度blockread函数读一个或多个记录到变量中blockwrite函数从变量中写一个或多个记录borderstyle属性边界类型borderwidth属性边界宽度break命令终止for、while、repeat循环语句brush属性画刷caption属性标签文字的内容changefileext函数改变文件的后缀chdir函数改变当前目录checked属性确定复选框选中状态chr函数返回指定序数的字符closefile命令关闭打开的文件color属性标签的颜色columns属性显示的列数comparestr函数比较字符串(区分大小写)concat函数合并字符串continue命令继续for、while、repeat的下一个循环copy函数返回一字符串的子串cos函数余弦函数ctl3d属性是否具有3d效果cursor属性鼠标指针移入后的形状date函数返回当前的日期datetimetofiledate函数将delphi的日期格式转换为dos的日期格式datetimetostr函数将日期时间格式转换为字符串datetimetostring函数将日期时间格式转换为字符串datetostr函数将日期格式转换为字符串dayofweek函数返回星期的数值dec函数递减变量值decodedate函数将日期格式分解为年月日decodetime函数将时间格式分解为时、分、秒、毫秒delete函数从字符串中删除子串deletefile命令删除文件diskfree函数返回剩余磁盘空间的大小disksize函数返回指定磁盘的容量dispose函数释放动态变量所占的空间disposestr函数释放字符串在堆栈中的内存空间ditherbackgrounddi2001.jpg?使背景色的色彩加重或减少50%dragcursor属性当鼠标按下时光标的形状dragmode属性按动的作用方式dropdowncount属性容许的显示数据项的数目editmask属性编辑模式enabled属性是否使标签呈现打开状态encodedate函数将年月日合成为日期格式encodetime函数将时、分、秒、毫秒合成为时间格式endmargin属性末尾边缘eof函数对有类型或无类型文件测试是否到文件尾eoln函数返回文本文件的行结束状态erase命令删除外部文件exceptaddr函数返回引起当前意外的地址exclude函数从集合中删除一些元素exceptobject函数返回当前意外的索引exit命令立即从当前的语句块中退出exp函数指数函数expandfilename函数返回包含绝对路径的字符串extendedselect属性是否允许存在选择模式,true时,multiselect才有意义extractfiledir函数返回驱动器和路径extractfileext函数返回文件的后缀extractfilename函数返回文件名extractfilepath函数返回指定文件的路径fileage函数返回文件已存在的时间fileclose命令关闭指定的文件filecreate命令用指定的文件名建立新文件filedatetodatetime函数将dos的日期格式转换为delphi的日期格式fileexists函数检查文件是否存在filegatattr函数返回文件的属性filegetdate函数返回文件的dos日期时间标记fileopen命令用指定的存取模式打开指定的文件filepos函数返回文件的当前指针位置fileread命令从指定的文件读取filesearch命令在目录中搜索指定的文件fileseek函数改变文件的指针filesetattr函数设置文件属性filesetdate函数设置文件的dos日期时间标记filesize函数返回当前文件的大小filewrite函数对指定的文件做写操作fillchar函数用指定的值填充连续字节的数findclose命令终止findfirst/findnext序列findfirst命令对指定的文件名及属性搜索目录findnext命令返回与文件名及属性匹配的下一入口floattodecimal函数将浮点数转换为十进制数floattostrf函数将浮点数转换为字符串floattostr函数将浮点数转换为字符串floattotext函数将给定的浮点数转换为十进制数floattotextfmt函数将给定的浮点数转换为十进制数flush函数将缓冲区的内容刷新到输出的文本文件中fmtloadstr函数从程序的资源字符串表中装载字符串fmtstr函数格式化一系列的参数,其结果以参数result返回font属性设置字体format函数格式化一系列的参数并返回pascal字符串formatbuf函数格式化一系列的参数formatdatetime函数用指定的格式来格式化日期和时间formatfloat函数指定浮点数格式frac函数返回参数的小数部分freemem函数按给定大小释放动态变量所占的空间getdir返回指定驱动器的当前目录getheapstatus返回内存管理器的当前状态getmem建立一指定大小的动态变量,并将指针指向该处getmemorymanager返回内存管理器的入口点glyph函数按钮上的图象halt停止程序的执行并返回到操作系统hi返回参数的高地址位high返回参数的上限值hint属性提示信息int返回参数的整数部分include添加元素到集合中insert在字符串中插入子串inttohex将整型数转换为十六进制数inttostr将整型数转换为字符串ioresult返回最新的i/o操作完成状态isvalidident测试字符串是否为有效的标识符items属性默认显示的节点kind属性摆放样式largechange属性最大改变值layout属性图象布局length函数返回字符串的动态长度lines属性缺省显示内容ln函数自然对数函数lo函数返回参数的低地址位loadstr函数从应用程序的可执行文件中装载字符资源lowercase函数将给定的字符串变为小写low函数返回参数的下限值max属性最大值maxlength属性最大长度min属性最小值mkdir命令建立一子目录move函数从源到目标复制字节multiselect属性允许同时选择几个数据项name属性控件的名字new函数建立新的动态变量并设置一指针变量指向它newstr函数在堆栈上分配新的字符串now函数返回当前的日期和时间odd测试参数是否为奇数onactivate事件焦点移到窗体上时触发onclick事件单击窗体空白区域触发ondblclick事件双击窗体空白区域触发onclosequery事件使用者试图关闭窗体触发onclose事件窗体关闭后才触发oncreate事件窗体第一次创建时触发ondeactivate事件用户切换到另一应用程序触发ondragdrop事件鼠标拖放操作结束时触发ondragover事件有其他控件从他上面移过触发onmousedown事件按下鼠标键时触发onmouseup事件释放鼠标键时触发onmousemove事件移动鼠标时触发onhide事件隐藏窗体时触发onkeydown事件按下键盘某键时触发onkeypress事件按下键盘上的单个字符键时触发onkeyup事件释放键盘上的某键时触发onpaint事件窗体上有新部分暴露出来触发onresize事件重新调整窗体大小触发onshow事件在窗体实际显示之前瞬间触发ord返回序数类的序数outlinestyle属性类型outofmemoryerror引起outofmemory意外pageindex属性页索引pages属性页paramcount函数返回在命令行上传递给程序的参数数量paramstr函数返回指定的命令行参数pen属性画刷设置pi函数返回圆周率pipicture属性显示图象pictureclosed属性设置closed位图pictureleaf属性设置leaf位图pictureminus属性设置minus位图pictureopen属性设置open位图pictureplus属性设置plus位图pos函数在字符串中搜索子串pred函数返回先前的参数random函数返回一随机函数randomize函数用一随机数初始化内置的随机数生成器read函数对有格式的文件,读一文件组件到变量中;对文本文件,读一个或多个值到一个或多个变量中readln函数执行read过程,然后跳到文件下一行readonly属性只读属性reallocmem函数分配一动态变量rename函数重命名外部文件renamefile函数对文件重命名reset函数打开已有的文件rewrite函数建立并打开一新的文件rmdir函数删除空的子目录round函数将实数值舍入为整型值runerror函数停止程序的执行scrollbars属性滚动条状态seek函数将文件的当前指针移动到指定的组件上seekeof函数返回文件的文件结束状态seekeoln函数返回文件的行结束状态selectedcolor属性选中颜色setmemorymanager函数设置内存管理器的入口点settextbuf函数给文本文件指定i/o缓冲区shape属性显示的形状showexception函数显示意外消息与地址sin函数正弦函数sizeof函数返回参数所占的字节数smallchange属性最小改变值sorted属性是否允许排序sqr函数平方函数sqrt函数平方根函数startmargin属性开始边缘state属性控件当前状态str函数将数值转换为字符串stralloc函数给以null结束的字符串分配最大长度-1的缓冲区strbufsize函数返回存储在由stralloc分配的字符缓冲区的最大字符数strcat函数将一字符串附加到另一字符串尾并返回合并的字符串strcomp函数比较两个字符串strcopy函数将一个字符串复制到另一个字符串中strdispose函数释放堆栈上的字符串strecopy函数将一字符串复制到另一个字符串并返回结果字符串尾部的指针strend函数返回指向字符串尾部的指针stretch属性自动适应控件的大小strfmt函数格式化一系列的参数stricomp函数比较两个字符串(不区分大小写)stringtowidechar函数将ansi字符串转换为unicode字符串strlcat函数将一字符串中的字符附加到另一字符串尾并返回合并的字符串strlcomp函数以最大长度比较两个字符串strlcopy函数将一个字符串中的字符复制到另一个字符串中strlen函数返回字符串中的字符数strlfmt函数格式化一系列的参数,其结果中包含有指向目标缓冲区的指针strlicomp函数以最大长度比较两个字符串(不区分大小写)strlower函数将字符串中的字符转换为小写strmove函数将一个字符串中的字符复制到另一个字符串中strnew函数在堆栈上分配一个字符串strpas函数将以null结束的字符串转换为pascal类的字符串strpcopy函数将pascal类的字符串复制为以null结束的字符串strplcopy函数从pascal类的最大长度字符串复制为以null结束的字符串strpos函数返回一个字符串在另一个字符串中首次出现指针strrscan函数返回字符串中最后出现字符的指针strscan函数返回字符串中出现首字符的指针strtodate函数将字符串转换为日期格式strtodatetime函数将字符串转换为日期/时间格式strtofloat函数将给定的字符串转换为浮点数strtoint函数将字符串转换为整型strtointdef函数将字符串转换为整型或默认值strtotime函数将字符串转换为时间格式strupper函数将字符串中的字符转换为大写style属性类型选择suce函数返回后继的参数swap函数交换参数的高低地址位tabs属性标记每一项的内容tabindex属性标记索引text属性显示的文本texttofloat函数将字符串(以null结束的格式)转换为浮点数time函数返回当前的时间timetostr函数将时间格式转换为字符串trim函数从给定的字符串中删除前导和尾部的空格及控制字符trimleft函数从给定的字符串中删除首部的空格及控制字符trimright函数从给定的字符串中删除尾部的空格及控制字符trunc函数将实型值截取为整型值truncate函数截去当前文件位置后的内容unselectedcolor属性未选中颜色upcase将字符转换为大写uppercase将给定的字符串变为大写val函数将字符串转换为整型值vararraycreate函数以给定的界限和维数建立变体数组vararraydimcount函数返回给定变体的维数vararrayhighbound函数返回给定变体数组维数的上界vararraylock函数锁定给定的变体数组vararraylowbound函数返回给定变体数组维数的下界vararrayof函数返回指定变体的数组元素vararrayredim函数通过改变上限来调整变体的大小vararrayunlock函数解锁指定的变体数组varastype函数将变体转换为指定的类型varcase函数将变体转换为指定的类型并保存它varclear函数清除指定的变体varcopy函数将指定的变体复制为指定的变体varformdatetime函数返回包含日期时间的变体varisarray函数测试变体是否为数组varisempty函数测试变体是否为unassignedvarisnull函数测试变体是否为nullvartodatetime函数将给定的变体转换为日期时间vartype函数将变体转换为指定的类型并保存它visible属性控件的可见性wantreturns属性为true时,按回车键产生一个回车符;为false时,按下ctrl+enter才产生回车符write命令对有格式的文件,写一变量到文件组件中;对文本文件,写一个或多个值到文件中writeln命令执行write过程,然后输出一行结束标志widecharlentostring函数将ansi字符串转换为unicode字符串widecharlentostrwar函数将unicode字符串转换为ansi字符串变量widechartostring函数将unicode字符串转换为ansi字符串widechartostrvar函数将unicode字符串转换为ansi字符串变量保留字Pascal中规定了一批单词,给这些单词赋予特定的含义,在进行程序设计时不能把这些单词重新定义或用于其它目的。
1. 连接运算concat(s1,s2,s3…sn) 相当于s1+s2+s3+…+sn.例:concat(‘11’,’aa’)=’11aa’;2. 求子串。
Copy(s,I,L) 从字符串s中截取第I个字符开始后的长度为l的子串。
例:copy(‘abdag’,2,3)=’bda’3. 删除子串。
过程Delete(s,I,l) 从字符串s中删除第I个字符开始后的长度为l的子串。
例:s:=’abcde’;delete(s,2,3);结果s:=’ae’4. 插入子串。
过程Inse rt(s1,s2,I) 把s1插入到s2的第I个位置例:s:=abc;insert(‘12’,s,2);结果s:=’a12bc’5. 求字符串长度length(s) 例:length(‘12abc’)=56. 搜索子串的位置pos(s1,s2) 如果s1是s2的子串,则返回s1的第一个字符在s2中的位置,若不是子串,则返回0.例:pos(‘ab’,’12abcd’)=37. 字符的大写转换。
Upcase(ch) 求字符ch的大写体。
例:upcase(‘a’)=’A’8. 数值转换为数串。
过程Str(x,s) 把数值x化为数串s.例:str(12345,s); 结果s=’12345’9. 数串转换为数值。
过程val(s,x,I) 把数串s转化为数值x,如果成功则i=0,不成功则I为无效字符的序数例:val(‘1234’,x,I);结果x:=1234求长度len gth定义:functi on Length(S: String): Intege r;例子:varS: String;beginReadln (S);Writel n('"', S, '"');Writel n('length = ', Length(S));end.复制子串co py定义:functi on Copy(S: String; Index:Intege r; Count:Intege r): String;注意:S 是字符串类型的表达式。
字符串类型在Borland公司的Turbo Pascal和16位Delphi中,传统的字符串类型是一个字符序列,序列的头部是一个长度字节,指示当前字符串的长度。
由于只用一个字节来表示字符串的长度,所以字符串不能超过255个字符。
这一长度限制为字符串操作带来不便,因为每个字符串必须定长(确省最大值为255),当然你也可以声明更短的字符串以节约存储空间。
字符串类型与数组类型相似。
实际上一个字符串差不多就是一个字符类型的数组,因为用[]符号,你就能访问字符串中的字符,这一事实充分说明了上述观点。
为克服传统Pascal 字符串的局限性,32位Delphi增加了对长字符串的支持。
这样共有三种字符串类型:∙ShortString 短字符串类型也就是前面所述的传统 Pascal 字符串类型。
这类字符串最多只能有255个字符,与16位Delphi中的字符串相同。
短字符串中的每个字符都属于ANSIChar 类型(标准字符类型)。
∙ANSIString长字符串类型就是新增的可变长字符串类型。
这类字符串的内存动态分配,引用计数,并使用了更新前拷贝(copy-on-write)技术。
这类字符串长度没有限制(可以存储多达20亿个字符!),其字符类型也是ANSIChar 类型。
∙WideString 长字符串类型与ANSIString 类型相似,只是它基于WideChar 字符类型,WideChar 字符为双字节Unicode 字符。
使用长字符串如果只简单地用String定义字符串,那么该字符串可能是短字符串也可能是ANSI长字符串,这取决于$H 编译指令的值,$H+(确省)代表长字符串(ANSIString 类型)。
长字符串是Delphi 库中控件使用的字符串。
Delphi 长字符串基于引用计数机制,通过引用计数追踪内存中引用同一字符串的字符串变量,当字符串不再使用时,也就是说引用计数为零时,释放内存。
如果你要增加字符串的长度,而该字符串邻近又没有空闲的内存,即在同一存储单元字符串已没有扩展的余地,这时字符串必须被完整地拷贝到另一个存储单元。
delphi字符串操作大全uses StrUtils;【字符串函数大全】首部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说明不区分大小写参考function pareString例子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说明区分大小写参考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, '是', '否') = '否'参考<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: TCustomEdit; 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(Memo1, Edit1.Text, SearchOptions);Memo1.SetFocus;end;///////End SearchBuf━━━━━━━━━━━━━━━━━━━━━首部function Soundex(const AText: string; ALength: TSoundexLength = 4):string; $[StrUtils.pas功能返回探测字符串说明根据探测法(Soundex)可以找到相进的字符串;/genealogy/coding.html参考<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: TCompareTextProc = 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;assembler; $[SysUtils.pas功能返回比较两个内存指针说明CompareMem(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 := CompareText(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(PChar(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转换成字符串说明Format('%d', [Value])参考function SysUtils.FmtStr例子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.FmtStr例子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 := StrToIntDef(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;━━━━━━━━━━━━━━━━━━━━━首部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;━━━━━━━━━━━━━━━━━━━━━首部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.AnsiSameText;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 CompareWith(const aArray: array of string): Boolean;varI: Integer;beginResult := False;for I := Low(aArray) to High(aArray) doif AnsiSameText(S, aArray[I]) thenbeginResult := True;Break;end;end;varLResult: Extended;beginResult := TryStrToFloat(S, LResult);if Result thenValue := LResult <> 0elsebeginResult := True; //修正处VerifyBoolStrArray;if CompareWith(TrueBoolStrs) thenValue := Trueelse if CompareWith(FalseBoolStrs) thenValue := 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.FmtStr;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;end;///////End StrPCopy━━━━━━━━━━━━━━━━━━━━━首部function StrPLCopy(Dest: PChar; const Source: string; MaxLen: Cardinal): PChar; $[SysUtils.pas功能返回将字符串Source指定长度MaxLen复制到指针字符串Dest中说明StrLCopy(Dest, PChar(Source), MaxLen)参考function SysUtils.StrLCopy例子///////Begin StrPLCopyprocedure TForm1.Button1Click(Sender: TObject);varvBuffer: array[0..255] of Char;beginStrPLCopy(vBuffer, Edit1.Text, SpinEdit1.Value);Edit2.Text := vBuffer;end;///////End StrPLCopy。
1. 连接运算concat(s1,s2,s3…sn) 相当于s1+s2+s3+…+sn.
例:concat(‘11’,’aa’)=’11aa’;
2. 求子串。
Copy(s,I,L) 从字符串s中截取第I个字符开始后的长度为l的子串。
例:copy(‘abdag’,2,3)=’bda’
3. 删除子串。
过程Delete(s,I,l) 从字符串s中删除第I个字符开始后的长度为l的子串。
例:s:=’abcde’;delete(s,2,3);结果s:=’ae’
4. 插入子串。
过程Insert(s1,s2,I) 把s1插入到s2的第I个位置
例:s:=abc;insert(‘12’,s,2);结果s:=’a12bc’
5. 求字符串长度length(s) 例:length(‘12abc’)=5
6. 搜索子串的位置pos(s1,s2) 如果s1是s2的子串,则返回s1的第一个字符在s2中的位置,若不是子串,则返回0.
例:pos(‘ab’,’12abcd’)=3
7. 字符的大写转换。
Upcase(ch) 求字符ch的大写体。
例:upcase(‘a’)=’A’
8. 数值转换为数串。
过程Str(x,s) 把数值x化为数串s.
例:str(12345,s); 结果s=’12345’
9. 数串转换为数值。
过程val(s,x,I) 把数串s转化为数值x,如果成功则i=0,不成功则I为无效字符的序数
例:val(‘1234’,x,I);结果x:=1234
求长度length
定义:function Length(S: String): Integer;
例子:
var
S: String;
begin
Readln (S);
Writeln('"', S, '"');
Writeln('length = ', Length(S));
end.
复制子串copy
定义:function Copy(S: String; Index: Integer; Count: Integer): String;
注意:S 是字符串类型的表达式。
Index和Count是整型表达式。
Copy 返回S中从Index 开始,Count个字符长的一个子串。
例子:
var S: String;
begin
S := 'ABCDEF';
S := Copy(S, 2, 3); { 'BCD' }
end.
插入子串insert
定义:procedure Insert(Source: String; var S: String; Index: Integer);
注意:Source 是字符串类型的表达式。
S 是任意长度字符串类型变量。
Index 是整型表达式。
Insert 把Source插在S中Index处。
如果结果字符串的长度大于255,那么255之后的字符将被删除。
例子:
var
S: String;
begin
S := 'Honest Lincoln';
Insert('Abe ', S, 8); { 'Honest Abe Lincoln' }
end.
删除子串delete
定义:procedure Delete(var S: String; Index: Integer; Count:Integer);
注意:S 是字符串类型变量。
Index和Countare是整型表达式。
Delete 删除S中从Index 开始的Count个字符。
如果Index大于S的长度,则不删除任何字符;如果Count大于S中从Index开始的实际字符数,则删除实际的字符数。
例子:
var
s: string;
begin
s := 'Honest Abe Lincoln';
Delete(s,8,4);
Writeln(s); { 'Honest Lincoln' }
Delete(s,9,10);
Writeln(s); { 'Honest L' }
end.
字符串转为数值val
定义:procedure V al(S; var V; var Code: Integer);
在这里:
S 是由一系列数字字符构成的字符串类型变量;。
V 是整型或实型变量;
Code 是Integer型变量
注意:V al将S转为它的数值形式。
例子:
var s:string;I, Code: Integer;
begin
s:='1234';
val(s,i,code);
writeln(i); { 1234 }
end.
数值转为字符串str
定义:procedure Str(X [: Width [: Decimals ]]; var S:string);
注意:将数值X转成字符串形式。
例子:
var
S: string[11];
begin
Str(I, S);
IntToStr := S;
end;
begin
Writeln(IntToStr(-5322));
Readln;
end.
求子串起始位置pos
定义:function Pos(Substr: String; S: String): Byte;
注意:Substr和S字符串类型表达式。
Pos在S中搜索Substr并返回一个integer值。
这个值是Substr的第一个字符在S中的位置。
如果在S中没有找到Substr,则Pos返回0。
例子:
var S: String;
begin
S := ' 123.5';
{ Convert spaces to zeroes }
while Pos(' ', S) > 0 do
S[Pos(' ', S)] := '0';
end.
字符完全串连+
定义:操作符+把两个字符串联在一起。
例子:
var s1,s2,s:string;
begin
s1:='Turbo ';
s2:='pascal';
s:=s1+s2; { 'Turbo pascal' }
end.
字符串压缩空格串连-
定义:操作符-去掉第一个字符串最后的空格后,将两个字符串联在一起。
例子:
var s1,s2,s:string;
begin
s1:='Turbo ';
s2:='pascal';
s:=s1-s2; { 'Turbopascal' }
end.。