Page 1 of 1
parse a string with double quotes
Posted: Sat Oct 21, 2006 9:22 am
by mikronos
Hi all,I currently test robotask for first time, and this my problem.I parse a text file wich contain this kind of string:Adresse IP : <span class="ip">82.254.254.254</span>And I want to put the ip address ( here 82.254.254.254 ) into a variable.For that I want to use basic fonction to extract the field.My problem is that the string to analyse contain double quote inside.When I evaluate the expression I got an error because in basic string statement the first argument must be double quoted.The expression:mid ("{c_line(0)}", 1,2) return an error because it is expanded as:mid ("Adresse IP : <span class="ip">82.254.254.254</span>",1,2)I have try many things like doubling the double quote, but nothing work.Can you help me ?Thanks in advance and forgive my bad english!
parse a string with double quotes
Posted: Tue Oct 24, 2006 9:54 am
by Oleg
Try to use the following script:
Sub Main
Dim Ln, addr As String
Dim p0,p1 As Integer
Ln = RoboTaskApp.ExpandText("{c_line}")
p0 = InStr(Ln,"ip"">")
p1 = InStr(Ln,"</span>")
If p0<>0 And p1 <>0 Then
addr = Mid(Ln,p0+4,p1-p0-4)
RoboTaskApp.SetUserVaria ble("IP_ADDR",addr)
Else
RoboTaskApp.SetUserVaria ble("IP_ADDR","")
End If
End Sub
The script extracts IP from variable {c_line} and assigns the address into variable IP_ADDR
parse a string with double quotes
Posted: Tue Oct 24, 2006 10:38 am
by mikronos
Thanks for the script.In fact I use two delimited variable to achieve this.The first delimited is for the char '>' and if found I create a second delimited variable for with the char '<' ... This one way in many...But the problem remain with the parameters passing between robot main and the basic module...Create a single variable and assign it a quoted string like this:object CreateVariable: Variable_Name = test Variable_Value = this is a "quoted" stringobject Evaluate: Expression to evaluate = left ("{test}", 1)And you are dead :(I dont know how the expression to evaluate is handled in internal, but the basic extension is not in cause for me. if I try a basic script like this:Sub Main a$ = "this is a " b$ = "quoted " c$ = "string" d$ = a$ & Chr(34) & b$ & Chr(34) & c$ e$ = Left(d$,3)End SubI have my quoted string in d$ and the function Left$ work correctly because d$ doesn't have a beginning and a end double-quote...Do you see the problem ? The first argument waited is a string, but the parser must remove the first and endding double-quote before evaluate the expression.
parse a string with double quotes
Posted: Wed Oct 25, 2006 3:38 am
by Oleg
That's right. In this case you must use the script.
RoboTask uses own variables as a macroexpansion.
I.e. expression
left ("{test}", 1)
transforms to expression
left ("this is a "quoted" string", 1)
This expression contain syntax error. The correct expression will be
left ("this is a ""quoted"" string", 1)
Maybe, it needed to add some string system variables, which can correct strings in BASIC functions.