Page 1 of 1
Get Part of String from Variable
Posted: Sun Feb 21, 2010 5:50 pm
by gpearson
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.
Re: Get Part of String from Variable
Posted: Sun Feb 21, 2010 8:31 pm
by BvG
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?
Re: Get Part of String from Variable
Posted: Mon Feb 22, 2010 3:03 am
by gpearson
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
Re: Get Part of String from Variable
Posted: Mon Feb 22, 2010 12:39 pm
by Mark
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
Re: Get Part of String from Variable
Posted: Mon Feb 22, 2010 10:59 pm
by gpearson
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
Re: Get Part of String from Variable
Posted: Mon Feb 22, 2010 11:13 pm
by Mark
Graham,
I gave you a function. Why don't you use it?
Best,
Mark
Re: Get Part of String from Variable
Posted: Mon Feb 22, 2010 11:42 pm
by gpearson
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