Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Argument in String Parsing, rekursiv
#1
Star 
Ich habe mal ein simples Beispiel vorbereitet, das einzelne Teile aus einem String herauslöst. Man kann das z.B. benutzen als Argumentparser, Wortzähler usw..

Es nutzt hier nur Leerzeichen als Trenner, man kann das aber natürlich anpassen auf ganze Strings von Worttrennern, wenn man will.

Code:
;CMD parse test by f.brandis
;

DEFTYPE.w

;parsetest cmds

cmd$="dump from %s to           %d    a b cde 4 6 jj m , . ."

NPrint ">",cmd$,"<"


Function.w stripnparse{inp$}         ;recursive!

 SHARED nums

 inp$=StripLead$(inp$,32)           ;strip leading SPC

 If inp$="" Then Function Return0   ;nothing left!

 spc1.w=Instr(inp$," ")             ;another separator?

 If spc1>1                          ;any SPC at the end of this inp$?

   arg1$=Mid$(inp$,spc1)

   out$ =Left$(inp$,spc1-1)

   Gosub _strpnprsprt

   ok=stripnparse{arg1$}            ;down the rabbit hole...

 Else                               ;rest is an arg.

   out$=inp$

   Gosub _strpnprsprt

 EndIf


 Function Return nums               ;global count

_strpnprsprt:

 nums+1

 NPrint "Arg"+Str$(nums)+": >",out$,"<"

Return

End Function

NPrint "#args: ",stripnparse{cmd$}

MouseWait

End

CloseEd
   
Zitieren


Nachrichten in diesem Thema
Argument in String Parsing, rekursiv - von hackball - 10.11.2019, 20:20

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 2 Gast/Gäste