您的位置:首页 > 编程语言 > Delphi

使用自定义分隔符分离字符串 解决Delphi7下TStringList.Delimiter分离无法跳过空格问题

2013-01-31 09:36 435 查看
{

函数功能:使用自定义分隔符分离字符串并以Stringlist返回

参数说明: 

Source: 源字符串

 Deli: 自定义分离符

StringList: 返回分离结果

}

procedure SplitString(Source,Deli:string; var StringList :TStringList);

var

  EndOfCurrentString: Integer;

begin

  if  StringList = nil then exit;

  StringList.Clear;

  while Pos(Deli, Source)>0 do

  begin

    EndOfCurrentString := Pos(Deli, Source);

    StringList.add(Copy(Source, 1, EndOfCurrentString - 1));

    Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);

  end;

  StringList.Add(source);

end;

// 调用

procedure TForm1.Button1Click(Sender: TObject);

var

  strlist: TStringList;

begin

  strlist := TStringList.Create;

  SplitString('123,Channel 1,00000000000000000123,上下线,离线,2013-01-31 09:22:32,公司',

    ',',

    strlist);

  ShowMessage(strlist.Text);

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐