Einzelnen Beitrag anzeigen

WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Split strings using string list

  Alt 12. Aug 2011, 10:24
Delphi-Version: 2010
Delphi-Quellcode:
function GetBarcodeCode (intNR : integer; AIndex : integer = 7): ansistring;
var
 strReturn : ansistring;
 strParse : TStringList;
 strRow : TStringlist;
 strCode : ansistring;
begin
 strReturn := GetBarcodesResult;
 strCode := '';
 if strReturn <> 'then
     begin
      strParse := TStringList.Create;
      strRow := TStringList.Create;
      strParse.Delimiter := #13;
      strParse.Text := strReturn;
      strRow.Delimiter := #9;
      if intNr <= strParse.Count then
          begin
          strRow.DelimitedText := strParse.Strings [intNR - 1];
          strCode := strRow.strings [AIndex - 1];
          end;
      FreeandNil (strParse);
      FreeandNil (strRow);
     end;
 GetBarcodeCode := strCode;
end;
Here is real API function from real project called INBarcodeOCR. It is nice problem demonstration.

Siply, it splits string first by CR control character and then by tabs. Split by CR is ok, but by tabs is invalid in case if space is available in string. If space is in string then it splits it as if this space is tab strRow should contain 8 items, because always in string are 7 tabs, but if space is inside, then it working as for 8 tabs

This is class bug or code is buggy? Can fix it using build-in Delphi functions?
  Mit Zitat antworten Zitat