Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract multiple words from one VARCHAR field 2

Status
Not open for further replies.

DarthGAD

IS-IT--Management
Mar 17, 2004
37
US
I have a database that stores the IP address' of a computer in one field separated by a space. If the computer is mulitihomed it may have mulitple IP address'.

I need to take the input:

Computer ID IpAdress'
11114444 192.168.1.1 10.254.44.3 162.168.160.1
22224444 169.254.180.185 10.254.55.1 162.168.160.3

And display each IP address separately as follows

Computer ID: 11114444
IP Address:
192.168.1.1
10.254.44.3
162.168.160.1

Computer ID: 22224444
IPAddress:
169.254.180.185
10.254.55.1
162.162.168.3

I don't just want to wrap the line to show all three. Any assistance will be greatly appreciated.

GusDarino
 
Try this formula, and format it as 'Can Grow':

stringvar array ip := Split({Table.Field}," ");
ip[1] := "Computer ID: " + ip[1] + chr(13) + "IP Address:";
join(ip, chr(13));

-dave
 
That will simply split them and put them on another line. I need to be able to completely separate them. This is because I may only want to display the Ip address for a particular subnet and not all the ones displayed. I apologize for not clarifying this earlier.

GusDarino
 
You can use formulas like the following to create individual "fields":

//{@IP1}:
if ubound(split({table.field}," ")) >= 1 then
split({table.field}," ")[1]

//{@IP2}:
if ubound(split({table.field}," ")) >= 2 then
split({table.field}," ")[2]

etc.

-LB
 
Ok then, using your examples from above, you would need at least 4 formulas:

//@ComputerID
//This would return the Computer ID based on your sample data
Split({Table.Field}, " ")[1];

//@IPAddress1
//This would get the first IP address (if it exists)
If UBound(Split({Table.Field}, " ")) >= 2 then
Split({Table.Field}, " ")[2]
Else
"";

//@IPAddress2
//This would get the second IP address (if it exists)
If UBound(Split({Table.Field}, " ")) >= 3 then
Split({Table.Field}, " ")[3]
Else
"";

//IPAddress3
//This would get the third IP address (if it exists)
If UBound(Split({Table.Field}, " ")) >= 4 then
Split({Table.Field}, " ")[4]
Else
"";

You can keep going with these as far as you need to. Then, I assume you would use each of the IPAddress formulas to test for a particular subnet.

-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top