使用自定義分隔符分離字符串 解決Delphi7下TStringList.Delimiter分離無法跳過空格問題

{

函數功能:使用自定義分隔符分離字符串並以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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章