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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting a String value 4

Status
Not open for further replies.

Halfcan

Technical User
Dec 8, 2002
214
US
Hello, I have a String Field of IP addresses, separated by semi colons.
Example: 10.0.0.1;10.0.0.2;10.0.0.3;10.0.0.4

I would like to find a way to pull out each individual IP address, to be used separately in other formulas.

Note that IP address may vary in character length.

Any Ideas?

I'm using CR V8.5

Thanks,
HC
 
This thread from this morning should help you out: thread767-847001

-dave
 
Thanks vidru,

I don't know if this is going to be possible, the number of IP addresses separted by semi colons will never be a fixed number, therefore I can't use the formula split (string,";") [a number].

I tried this formula:

Local StringVar String := {String} ;
Local StringVar Array Values := Split(String,";");
Local StringVar Result := "";
Local NumberVar Counter := 0;
While Counter <> UBound(Values) Do
(Counter := Counter + 1;
Result := Result &Space(12-Len(Values[Counter]))& Values[Counter];);
Result;

but the result just removes the ; and adds spaces between the ip addresses...like this: 10.0.0.1 10.0.0.2 10.0.0.3

I'm looking for 3 individual values to be generated and I'm starting to wonder if this is even possible.

Thanks again,
HC


 
you have your individual results in the Array....what do you want to do with them...if it is just to print them then you have done that....if not...what is your purpose.

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Use a split with array location.

For the first loaction:

split({your.field},";")[1]



Mike
 
If you're trying to pull individual IP addresses out for other formulas, here's an example using 4 separate formulas:
[tt]
// @IPAddr1
StringVar Array t := Split({Table.Field},";");

If t[1] = "" Then "" Else t[1];


// @IPAddr2
StringVar Array t := Split({Table.Field},";");

If Count(t) > 1 Then
If t[2] = "" Then
""
Else
t[2]
Else
"";


// @IPAddr3
StringVar Array t := Split({Table.Field},";");

If Count(t) > 2 Then
If t[3] = "" Then
""
Else
t[3]
Else
"";


// @IPAddr4
StringVar Array t := Split({Table.Field},";");

If Count(t) > 3 Then
If t[4] = "" Then
""
Else
t[4]
Else
"";
[/tt]
You can continue with this as far as you need to...

-dave
 
I am looking to use each IP address in a formula.
Our company is a Network Operations Center. We watch networks and report on network outages. When there is an outage, a Ticket# (record) is created, and the affected IP's are recorded within that ticket (record)

If we have an outage that only affects 1 Device (IP), then it's no problem to do calculations because we are working with only 1 IP value per record.
Ex: Ticket 100, IP value=10.0.0.1

But when multiple IP's are listed in ONE record (ticket), it's now
Ex: Ticket 100 IP value=10.0.0.1;10.0.02;10.0.0.3

Take Uptime% for example. Devices 10.0.0.1 and 10.0.0.2 go down. I'm looking to calculate Uptime percentage for EACH IP
even through are part of the SAME record. (ticket).
The uptime% calculation for each IP will have to share the same date and time values for that record.

Each ticket contains data such as: Ticket#, Date Down, Time Down, Date UP, Time UP,. These are all single values within the record. So the multiple ip string needs to be split into individual IP's, then each ip needs to be calculated against the common date and time values of the ticket.

I hope this makes sense.
Thanks,
HC
 
Thanks vidru. Unfortunately I will not ever know how many IP's are selected with the multi-select field. There could be 2 ips, or 20 ip's.
I will check it out...
HC
 
You still haven't defined what you need to do with this data, you just keep saying that you need them as seperate data fields.

The following will generally net the best results here, and minimize these BLOG type posts:

Crystal version
Database/Connectivity used
Example data
Expected output

I would approach this by creating an intelligent data source on the database, whoever designed this table needs to go back to their data entry job.

Since you've tried the WHILE LOOP formula, note that while in that loop you can individually check use each IP address.

If you just want to display them on seperate lines, change the formula Dave supplied to:

join(Split({Table.Field},";"),chr(13))

-k

-k
 
THE ONLY THING I'VE HAVEN'T DEFINED IS THE DATABASE TYPE.
MYSQL.
FORGET IT.
 
OK, it's forgotten, but you didn't define the expected output.

Don't blame others for asking you for additional information, you never stated what you wanted to do with the data, just that you want it.

They supplie it to you, and you said that it isn't whaat you want, but not what you need it for.

Think of a technical post as a mini-spec, or a tech suppor call, the items I identified are what both would require.

Go ahead and try posting again, I promise not to respond to you for fear of upsetting you further.

-k
 
Hi,

The Split function
( StringVar Array t := Split({Table.Field},";")
creates an array of n entries ( n = number of values chosen in the multi-select field)
By using a Loop from 1 to Count(t)
you can access each address in the list and do whatever you want with it.
The Count will tell you how many are in the list.

[profile]

 
Just to supplement what Turkbear posted, Crystal also has a function that gives you the upper boundary of an array.

UBound(array_name)

would give you the largest element number of the array. UBound could be used instead of Count(t).

If you needed to loop through an array you could UBound to determine the end of the loop like this:

Code:
numberVar i;

for i := 1 to ubound(t) do
(
    stringVar result := result & t[i] & chr(13)
);

result;

THis example does the same thing that synapsevampire posted with the combination of the split and join functions, but I just wanted to demonstrate a simple example of how you could use the UBound function.

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top