Recent

Author Topic: Here is why I asked.  (Read 5857 times)

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Here is why I asked.
« Reply #15 on: February 16, 2018, 02:52:50 am »
Here is something I Just whipped up for a simple line parser.. Educational purposes only  :D
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. Const TheInputStr:String = '*Boeing767-300ER       \P3d            \plugins\757767Avionics\routes\';
  3. var
  4.   WordCount,I :Integer;
  5.   Entries :Array[1..4] of string;
  6. Function GetParserWord(Var parserindex:Integer; InStr:String):String;
  7.  begin
  8.    Result := '';
  9.    // First remove spaces.
  10.    While (ParserIndex <= Length(InStr))and(InStr[ParserIndex] in [#8,' '])
  11.     do Inc(ParserIndex);
  12.    While (ParserIndex <= Length(INStr))and (Not (InStr[ParserIndex] in[#8,' ']))
  13.     do
  14.      Begin
  15.       Result := Result+Instr[ParserIndex];
  16.       Inc(ParserIndex);
  17.      End;
  18.  End;
  19. Function BuildWordArray(InStr:String):Integer;
  20. Var
  21.   I:Integer;
  22. Begin
  23.   For I := Low(Entries) to High(Entries) do Entries[I] := '';
  24.   Result := 1;
  25.   I := 1;
  26.   Repeat
  27.    Entries[Result] := GetParserWord(I,Instr);
  28.    Inc(Result);
  29.   until (Entries[Result-1] = '') or(Result > High(Entries));
  30.   Result := Result-1;
  31. end;
  32.  
  33. begin
  34.  WordCount := BuildWordArray(TheInputStr);
  35.  For I := 1 To WordCount do
  36.   WriteLn(Entries[I]);
  37.   ReadLn;
  38. end.
  39.  
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018