Page 1 of 1

Parse from variable [SOLVED]

Posted: Thu Nov 05, 2015 5:09 pm
by LiK137
I want to know whether its possible or not:

Code: Select all

Procedure.s ip()
  ip$=HostnameToIP("P")  
  ProcedureReturn ip$
EndProcedure

InitNetwork()

MACadr$=GetMacAddress("192.168.1")

; cmd$="mkdir %TEMP%\@#ip()#@"
cmd$="rename %TEMP%\@#ip()#@ %TEMP%\@#RemoveString("+Chr(34)+MACadr$+Chr(34)+", "+Chr(34)+":"+Chr(34)+")#@"
Repeat
  oldcmdelimerstart=cmdelimerstart:oldcmdelimerend=cmdelimerend
;   i+1
  cmdelimerstart=FindString(cmd$,"@#",cmdelimerstart+1)
  cmdelimerend=FindString(cmd$,"#@",cmdelimerend+1)
  cmdx$=Mid(cmd$,cmdelimerstart+2,cmdelimerend-cmdelimerstart-2)
  ; Here I need to get string value of purebasic operation stored in cmdx$
  cmdx$=ParseString(cmdx$)  ; ParseString() - Is that possible???
  Debug cmdx$;+Str(i)+"  oldstart:"+Str(oldcmdelimerstart)+"  start:"+Str(cmdelimerstart)+"  oldend:"+Str(oldcmdelimerend)+"  end:"+Str(cmdelimerend)
Until cmdelimerstart<oldcmdelimerstart And cmdelimerend<oldcmdelimerend
Debug "Finita"
Here I need to get string value of purebasic operation stored in cmdx$
cmdx$=ParseString(cmdx$) ; ParseString() - Is that possible???

Re: Parse from variable

Posted: Sun Nov 08, 2015 1:52 am
by Amilcar Matos
Maybe what you are looking for is this. From PureBasic help file;
Syntax
Result$ = StringField(String$, Index, Delimiter$)
Description
Returns the string field at the specified index.

Hope it helps!
:D

Re: Parse from variable

Posted: Sun Nov 08, 2015 6:59 am
by Demivec
LiK137 wrote:Here I need to get string value of purebasic operation stored in cmdx$
cmdx$=ParseString(cmdx$) ; ParseString() - Is that possible???
If by parse you mean you only want to know the portion of the string that contains the command then use something similar to what Amilcar Matos suggested.

If you want to execute the command that you parsed then the answer is no, you can't do it. That would require PureBasic to compile that string and then execute it, which it won't.

You can build a parser and then execute the parsed commands. This would vary in complexity with the commands and their parameters that were possible and whether they were static (always the same) or changing.