Get Part of String from Variable

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Get Part of String from Variable

Post by gpearson » Sun Feb 21, 2010 5:50 pm

If this question has been asked before, please direct me to the right location so that I can enhance my learning of RR

In my stack as I am learning RR over the past few weeks, I am stuck with trying to extract a section of text from the following lline of code.

Code: Select all

put shell("ipconfig") into tIPAddress
What I am trying to do is take this information and locate the line that starts with IPv4 and put the right value of this line into a new variable that I can display on a field label of my stack. Once I can work this out for WIndows, I will do the same thing for Linux and be able to post the function back to public domain.
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Get Part of String from Variable

Post by BvG » Sun Feb 21, 2010 8:31 pm

i think this is part of glx application framework by blue mangos trevor devore. it's open source and so maybe you can take the version in there out, and edit or enhance it?
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Re: Get Part of String from Variable

Post by gpearson » Mon Feb 22, 2010 3:03 am

While reading information from this framework, I discovered a command that might be able to get me the right information. The command is matchText however, I am stuck right now on the regular expressions.

I did find a sample of code which will display the mac address

Code: Select all

get matchText(temp,"Physical Address[\. ]*: ([A-Z0-9-]*)",retVal)
In this example I replaced Physical Address with IPv4 Address and struggling on what to put within the () to get the 4 sections of the ip address. Any Ideas
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Get Part of String from Variable

Post by Mark » Mon Feb 22, 2010 12:39 pm

gpearson ,

What about this? Will work on Windows only. This function will often return empty, if you try to retrieve information for a connection names IPv4.

Code: Select all

function getConnectionIP theConnection
  put shell("ipconfig /all") into myData
  filter myData with ("*" & theConnection & "*")
  set the itemDel to colon
  return item 2 of myData
end getConnectionIP
Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Re: Get Part of String from Variable

Post by gpearson » Mon Feb 22, 2010 10:59 pm

Mark wrote:gpearson ,

Code: Select all

function getConnectionIP theConnection
  put shell("ipconfig /all") into myData
  filter myData with ("*" & theConnection & "*")
  set the itemDel to colon
  return item 2 of myData
end getConnectionIP
Is their a way to view the information from the filter command in an answer line. As I learn RR I am trying to use a practical application which allows me to grasp the concepts better.

Code: Select all

filter myData with ("IP?4 Address")
now my next line is answer information myData which returns a blank window. If I look in a command prompt ipconfig /all I show a line that has IPv4 and after the colon has 172.27.14.55
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Get Part of String from Variable

Post by Mark » Mon Feb 22, 2010 11:13 pm

Graham,

I gave you a function. Why don't you use it?

Code: Select all

answer getConnectionIP("IPv4")
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gpearson
Posts: 84
Joined: Wed Feb 03, 2010 12:55 pm

Re: Get Part of String from Variable

Post by gpearson » Mon Feb 22, 2010 11:42 pm

I am trying to understand the function and changing it so I can grasp the concept. I will research how to use the function.

I am a learner of trial and error and when I can grasp the concepts I will be able to teach others
---
Graham Pearson
Goshen, IN USA

We Are Closed Today is your single internet resource for Indiana Area School Closings, Visit http://www.weareclosedtoday.com

Post Reply