Delphi 字符串操作
来源:互联网 发布:手机防盗软件 编辑:程序博客网 时间:2024/06/05 20:12
常忘记,在此做笔记。
这几个函数都包含在StrUtils中,所以需要uses StrUtils;
假设字符串是 Dstr := ’Delphi is the BEST’, 那么
LeftStr(Dstr, 5) := ’Delph’
MidStr(Dstr, 6, 7) := ’i is th’
RightStr(Dstr, 6) := ’e BEST’
~~~~~~~~~~~~~~~~~~~~~~~~~
function RightStr
(Const Str: String; Size: Word): String;
begin
if Size > Length(Str) then Size := Length(Str) ;
RightStr := Copy(Str, Length(Str)-Size+1, Size)
end;
function MidStr
(Const Str: String; From, Size: Word): String;
begin
MidStr := Copy(Str, From, Size)
end;
function LeftStr
(Const Str: String; Size: Word): String;
begin
LeftStr := Copy(Str, 1, Size)
end;
这几个函数经常结合Pos, Length, Copy使用
拆分字符串的函数 [2005-12-13]
delphi中没有提供此类函数,从大富翁找了一个
function split(src,dec : string):TStringList;
var
i : integer;
str : string;
begin
result := TStringList.Create;
repeat
i := pos(dec,src);
str := copy(src,1,i-1);
if (str='') and (i>0) then
begin
delete(src,1,length(dec));
continue;
end;
if i>0 then
begin
result.Add(str);
delete(src,1,i+length(dec)-1);
end;
until i<=0;
if src<>'' then
result.Add(src);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ss : TStringList;
str,dec : string;
begin
str := '1111||2222||||3333|||4444||';
dec := '||';
ss := split(str,dec);
memo1.Lines.AddStrings(ss);
ss.Free;
end;
- Delphi 字符串操作
- delphi字符串操作
- Delphi 字符串操作
- delphi 字符串操作
- delphi中的字符串操作
- delphi中的字符串操作
- DELPHI 字符串、数组操作函数
- DELPHI字符串、数组操作函数
- DELPHI字符串、数组操作函数
- DELPHI字符串、数组操作函数
- DELPHI字符串、数组操作函数
- DELPHI字符串、数组操作函数
- delphi字符串操作函数一览
- DELPHI字符串、数组操作函数
- delphi字符串操作函数一览
- DELPHI字符串、数组操作函数
- delphi字符串操作函数一览
- DELPHI基础:字符串、数组操作函数
- 我的程序员之路
- 其沃尔沃确认
- 转 log4j配置文件中的问题
- Eclipse单步调试快捷键
- iPhone开发入门教程[转]
- Delphi 字符串操作
- 传智播客--UBUNTU搭建JAVA EE开发环境
- [Microsoft][SQLServer 2000 Driver for JDBC]Object has been closed.
- 第三章 - 数据和C
- WAS进程消失
- ajax 方法
- 孤独的时候需要沉淀
- 人渐渐成熟的15个迹象
- 优秀程序员应该具备哪些素质