Getting string from X position until the end of text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: Getting string from X position until the end of text

Post by jiml » Tue Feb 24, 2015 6:41 pm

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

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: Getting string from X position until the end of text

Post by jiml » Tue Feb 24, 2015 6:48 pm

also

Code: Select all

filter theText without ""
no longer needed since

Code: Select all

filter theText with "*=*"
eliminates empty lines

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Getting string from X position until the end of text

Post by Thierry » Tue Feb 24, 2015 7:01 pm

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 :roll:
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Getting string from X position until the end of text

Post by jacque » Tue Feb 24, 2015 8:17 pm

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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Getting string from X position until the end of text

Post by Thierry » Wed Feb 25, 2015 9:19 am

jacque wrote:I'd just do this:
Junk apart, you'll miss part of some values..

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Getting string from X position until the end of text

Post by Thierry » Wed Feb 25, 2015 9:39 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

dbm
Posts: 21
Joined: Tue Feb 17, 2015 1:12 pm

Re: Getting string from X position until the end of text

Post by dbm » Wed Feb 25, 2015 10:30 am

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Getting string from X position until the end of text

Post by jacque » Thu Feb 26, 2015 2:26 am

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply