(1)大小写转换函数
function UpperCase(const s:string):string;
说明:将s字符串中的所有小写字母转化成大写字母,其他字符不变。
function LowerCase(const s:string):string;
说明:将s字符串中所有的大写字母转化成小写字母,其他字符不变。
(2)比较字符串大小的函数
function CompareStr(const s1,s2:string):Integer;
说明:s1>s2返回大于0的数,s1=s2返回0,s1<s2返回负数。
(3)将一个或者多个字符串连接起来的函数
function Concat(s1 [,s2,....sn]:string):string;
说明:将s1,s2。。。sn依次连接起来
(4)查找字符串函数
function Pos(substr:string;s:string):integer;
说明:返回subetr字符在s字符串中的位置,如果占不到substr则返回0。
(5)取自字符串函数
function Copy(s;index,count:integer):string
说明:在s中从第index位置开始取长度为count的字符串。如果count大于s字符串长度,则取空串;如果从index开始到最后不足count个字符,则取从index开始的所有字符串。
(6)求字符串长度的函数
function Length(a):integer;
说明:返回字符串长度。
(7)去掉字符串前置不可见字符的函数
function TrimLeft(const s:string):string;overload;
function TrimLeft(const s:Widestring):Widestring;overload;
说明:去掉s字符串的前置不可见字符,然后再返回s。s可以是字符型或者宽字符型。小于或者等于#32的字符看作不可见字符。
(8)去点字符串右边不可见字符的函数
function TrimRight(const s:string):string;overload;
function TrimRight(const s:Widestring):Widestring;overload;
说明:去掉s字符串的右边不可见字符,然后再返回s。s可以是字符型或者宽字符型。小于或者等于#32的字符看作不可见字符。
(9)去掉字符串前置盒后面不可见字符的函数
function Trim(const s:string):string;overload;
function Trim(const s:Widestring):Widestring;overload;
说明:去掉s字符串的前置和后面不可见字符,然后再返回s。s可以是字符型或者宽字符型。小于或者等于#32的字符看作不可见字符。
(10)删除子字符串的过程
procedure Delete(var s:string; index, count:integer);
说明:用来在字符串s中删除从index开始,count个字符长的子字符串。如果index大于字符串长度,则不删除;如果index到字符结尾不足count个字符,则删除除index只有的所有字符。
(11)插入字符串的过程
procedure Insert(source:string;var s:string;index:integer);
说明:将source字符串插入到s中的第index字符出。
program Stringfun;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
st:string;
ss:string;
begin
{ TODO -oUser -cConsole Main : Insert code here }
st:='ABC123abc';
ss:='.-QWE123qwe';
Writeln('st小写变大写:',uppercase(st));
Writeln('ss大写变小写:',lowercase(ss));
Writeln('st与ss比大小:',comparestr(st,ss)); //st>ss返回大于0的数,st=ss返回0,st<ss返回负数
Writeln('st连接ss:',concat(st,ss));
Writeln('查找a在st中的位置:',Pos('a',st));
Writeln('截取ss中第2个位置开始的3个字符:',Copy(ss,2,3));
Writeln('st的长度:',Length(st));
Writeln('去掉ss前后不可见字符',trim(ss));
//删除st中第2个开始的3个字符;
Delete(st,2,3);
Writeln(st);
//把ha插入到st字符串的第3字符处;
Insert('cfn',ss,2);
Writeln(ss);
Readln;
end.