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

Split Array Help

Status
Not open for further replies.

BlurredVision

Technical User
Aug 6, 2001
326
GB
I have a field with a delimiter of a comma (Example: DR PEPPER, COKE, 7UP, PEPSI)
My goal is to split up the field split({field_name}, “,”) then do some and if statements against the data

If “COKE” then
“Can remove the rust off of a ford pinto” else
If “PEPSI” then
“Southerners like adding peanuts to Pepsi” else “”


My dilemma is, because the field can contain so many values, I would like to figure out a way to dynamically add the values to a variable..

Meaning, I don’t want to do:

If array[1] = “COKE” then true else
If array[2] = “PEPSI” then false

I would like to do something along the lines of
if array = “COKE” then true else
if array = “PEPSI” then false

I am just attempting to simply things. I would think this could be done with a counter, but I am not 100%

I hope this makes sense
 
Hi,
Since the Split function creates an array,
and
Count(Array} returns how many there are, you can loop thru them and test each value..This is the only way I know of to determine the contents of an array.
Your desired method:

if array = “COKE” then true else
if array = “PEPSI” then false

cannot work,since the array must be subscripted.


[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Something like
If "COKE" in myArray then "Not Bad"
else if "PEPSI" in myArray then "Yuck"
else if "Dr. Pepper" in myArray then "mmmmmm Good!!"

Bob Suruncle
 
Hi,
From BlurredVision's example it seemed that myArray could contain all those names ( just like the original string field) so a simple If..Then..Else on the entire array ( or the string field itself) would stop when the first one resolves to True..I assumed that multiple actions/tests were wanted (or just different outcomes, maybe, based on each Product name found)..






[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Thanks for all the info guys. I ended up creating a loop to test each value.

 
shared stringvar array pList;
pList[1] := split("1111-2222","-",2)

My intent is to capture "1111" in a variable then process accordingly. When used in a formula I can't save. I get an error "array must be subscripted....example". Why? The documentation says that split returns an array. Is this not the way to capture it's output? If not, how do I do this? Your expertise is appreciated.

Thanks,
NMMI
 
The following will return the first element of the array:

split("1111-2222","-")[1]

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top