Page 2 of 2
Re: Getting string from X position until the end of text
Posted: Tue Feb 24, 2015 6:41 pm
by jiml
NO, that was not better. This is:
Code: Select all
function getVariables theText
repeat with x = 1 to the number of words of theText --down to 1
if word x of theText contains "=" then put cr before word x of theText
end repeat
filter theText without ""
filter theText with "*=*"
replace quote with empty in theText
split theText with cr and "="
return theText
end getVariables
Re: Getting string from X position until the end of text
Posted: Tue Feb 24, 2015 6:48 pm
by jiml
also
no longer needed since
eliminates empty lines
Re: Getting string from X position until the end of text
Posted: Tue Feb 24, 2015 7:01 pm
by Thierry
dbm wrote:Merci monsieur Douez!
The data is chaotic <...>
the data returned by the router for the identifier "last-seen" comes in the format date time without quotes.
Well, chaotic might be a bit too much, (I've seen worse) but let say inconsistent or a bit tricky
In this case yes, but is not the same case always (see example from another answer from router):
Ok, so it's a NO answer.
0 customer=admin user="user1" nas-port=2147483656 nas-port-type=ethernet nas-port-id="ether1" calling-station-id="00:1D:72:8E:C0:35" user-ip=10.0.1.194 host-ip=127.0.0.1
status=start,stop,interim from-time=feb/09/2015 22:11:07 till-time=feb/09/2015 22:13:49 terminate-cause=user-request uptime=2m42s download=71441 upload=27396
Are the return chars significant, or your datas are soft wrapped?
Do you have other kind of datas before I spend some times on it?
Regards,
Thierry
Re: Getting string from X position until the end of text
Posted: Tue Feb 24, 2015 8:17 pm
by jacque
I'd just do this:
Code: Select all
function getVar pData,pVar
replace cr with space in pData
split pData by space and "="
return pData[pVar]
end getVar
The resulting array will contain a lot of junk entries and empty variables, but if you are asking for a particular known variable it doesn't matter. The junk in the array won't hurt anything. If you plan to loop through the array to collect all the variables then it does matter and you'll need to clean up the data before using the function.
To use the function:
Code: Select all
put getVar(tData,"password") into tValue
Re: Getting string from X position until the end of text
Posted: Wed Feb 25, 2015 9:19 am
by Thierry
jacque wrote:I'd just do this:
Junk apart, you'll miss part of some values..
Regards,
Thierry
Re: Getting string from X position until the end of text
Posted: Wed Feb 25, 2015 9:39 am
by Thierry
dbm wrote:
0 customer=admin user="user1" nas-port=2147483656 nas-port-type=ethernet nas-port-id="ether1" calling-station-id="00:1D:72:8E:C0:35" user-ip=10.0.1.194 host-ip=127.0.0.1
status=start,stop,interim from-time=feb/09/2015 22:11:07 till-time=feb/09/2015 22:13:49 terminate-cause=user-request uptime=2m42s download=71441 upload=27396
Ok, my 2 lines script using a regex is working fine with your previous data + these ones.
I didn't see it was the Beginner's forum with my 1st reply.
Therefore, if you are *really* interested to code with some regex ,
please contact me off-list. No worries, it will be free
Regards,
Thierry
Re: Getting string from X position until the end of text
Posted: Wed Feb 25, 2015 10:30 am
by dbm
First of all, thanks to all for your answers and the quality of them.
I would clarify something:
The application that I'm developing is a visual interface to a router, using ssh to interact with it. I decided to use Livecode for the ability to generate binaries in windows/linux/OSX and 'cause the learning curve seemed good for me (sometimes is a little roller coaster) and of course, I can use the ssh external!
I wanna release this application under GPLv3 in few days.
Re: Getting string from X position until the end of text
Posted: Thu Feb 26, 2015 2:26 am
by jacque
Thierry wrote:jacque wrote:I'd just do this:
Junk apart, you'll miss part of some values..
Right, I didn't notice the values that had more than one word.