图片下载- -| 回首页 | 2005年索引 | - -小灵通网关模拟器

分割、合并字符串的Delphi程序

                                      

  编写了两段小程序,Split是用来分割字符串的,把字符串分割成了一个TStringList对象;Splice是用来合并字符串的,把一个StringList对象合并为一个字符串。
  注:只因为不知道TStringList的Delimiter和DelimitedText才编写的。

procedure Split(const Source, Delimiter: string;
  var RetVal: TStringList);
var
  bPos, ePos, len: integer;
begin
  bPos := 1;
  ePos := PosEx(Delimiter, Source);
  if not Assigned(RetVal) then
     RetVal := TStringList.Create;
  while ePos >= bPos do
  begin
     RetVal.Add(MidStr(Source, bPos, ePos - bPos));
     bPos := ePos + 1;
     ePos := PosEx(Delimiter, Source, bPos);
  end;
  len := Length(Source);
  if bPos < len then
  RetVal.Add(MidStr(Source, bPos, len - bPos + 1));
end;

procedure Splice(Const Source: TStrings;
  const Delimiter: string; var RetVal: string);
var
  i, imax, len: integer;
begin
  len := Length(Delimiter);
  imax := Source.Count - 1;
  RetVal := '';
  for i := 0 to imax do
     RetVal := Delimiter + Source[i];
  if Length(RetVal) > len then
     Delete(RetVal, 1, len);
end;

【作者: 胡传魁】【访问统计:】【2005年07月14日 星期四 10:16】【 加入博采】【打印

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=2265076

博客手拉手

澡堂会拍照权与务实的知识产权保护
大韩釜山365天特价v
宾馆家具|办公家具
《三国群英传5》超级秘籍大全(1)
清纯的远方

回复

验证码:   
评论内容: