deliphi 字符串分割_delphi中拆分字符串的函数

delphi的字符截取函数LeftStr, MidStr, RightStr拆分字符串

这几个函数都包含在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;

分享到:

2009-06-29 13:01

浏览 2237

评论

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值