1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49:
| procedure ScanF(const AText: string; ADelim: Char; ATarget: array of PChar); var CurTargetIndex, CurTargetLength: Integer; CurTarget, CurChar: PChar; begin CurTargetIndex := 0; CurChar := PChar(AText); CurTarget := CurChar; while (CurChar^ <> #0) or (CurTarget <> nil) do begin if (CurChar^ = ADelim) or (CurChar^ = #0) then begin if CurTarget <> nil then begin if CurTargetIndex >= Length(ATarget) then raise Exception.Create('Not enough space in array for ScanF(''' + AText + ''')'); CurTargetLength := Integer(CurChar) - Integer(CurTarget); CopyMemory(ATarget[CurTargetIndex], CurTarget, Succ(CurTargetLength)); ATarget[CurTargetIndex][CurTargetLength] := #0; Inc(CurTargetIndex); CurTarget := nil; end; end else if CurTarget = nil then CurTarget := PChar(CurChar); Inc(CurChar); end; end;
procedure TForm235.Button1Click(Sender: TObject); var ExampleString, a, b, c, d, e, f: string; begin ExampleString := 'BEZ :STUNDE (E/Ex/A/Ax/M/Mx/SM/SMx/T/Z/TN/B2/B8/B16/ANZ) (I/O) EW I'; SetLength(a, Length(ExampleString)); SetLength(b, Length(ExampleString)); SetLength(c, Length(ExampleString)); SetLength(d, Length(ExampleString)); SetLength(e, Length(ExampleString)); SetLength(f, Length(ExampleString)); ScanF(ExampleString, ' ', [PChar(a), PChar(b), PChar(c), PChar(d), PChar(e), PChar(f)]); SetLength(a, StrLen(PChar(a))); SetLength(b, StrLen(PChar(b))); SetLength(c, StrLen(PChar(c))); SetLength(d, StrLen(PChar(d))); SetLength(e, StrLen(PChar(e))); SetLength(f, StrLen(PChar(f))); ShowMessage(a + #13#10 + b + #13#10 + c + #13#10 + d + #13#10 + e + #13#10 + f); end; |