Page 1 of 1
get unique values from text
Posted: Thu Dec 20, 2012 11:12 am
by dbcbos
Hi all,
is there a way to get unique values from text eg:
I have the following text in a field
Code: Select all
product
product
product
service
item
item
item
item
and I like the following outcome
I know I could loop over all lines save all unknown words/items in a Dictionary/Array and skip if it is among the lines of my dictionary array. Just wondering if there is a better way to do this?
Basically what I am trying to do is get all unique tags in an XML File.
Re: get unique values from text
Posted: Thu Dec 20, 2012 11:51 am
by Klaus
HI dbcbos,
the fastest way is to create an array like this:
Code: Select all
on mouseUp
put fld 1 into tF
put empty into tArray
## We create an ARRAY where your entries are the keys
## with the trick of adding something to the CONTENT of the keys,
## we will end with the unique names of your entries
repeat for each line i in tF
add 1 to tArray[i]
end repeat
## We don't need the CONTENT of the array, just the KEYS, which are now what we are looking for :-)
put keys of tArray into fld 2
end mouseUp
"fld 1" contains your doublette strings, "fld 2" will show all entries without the doublettes:
service
product
item
Best
Klaus
Re: get unique values from text
Posted: Thu Dec 20, 2012 11:55 am
by dbcbos
Oh joy. That's a sly hack. Thanks.
Re: get unique values from text
Posted: Thu Dec 20, 2012 12:10 pm
by Klaus
Re: get unique values from text
Posted: Thu Dec 20, 2012 1:15 pm
by Mark
Hi,
I don't know if it executes quicker, but it is less code:
Code: Select all
put field "Your List" into myListArray
split myListArray by cr and tab
combine myListArray by cr and tab
Kind regards,
Mark
Re: get unique values from text
Posted: Thu Dec 20, 2012 1:22 pm
by Klaus
Hi Mark,
hmm, I get this result with your script:
product
product
product
service
item
item
item
item
Not really what I exspected
Best
Klaus
Re: get unique values from text
Posted: Thu Dec 20, 2012 1:28 pm
by Mark
Klaus, try again
Mark
Re: get unique values from text
Posted: Thu Dec 20, 2012 1:58 pm
by Klaus
Same script, same result
Yep, with "and tab" it surely works...
Re: get unique values from text
Posted: Thu Dec 20, 2012 2:07 pm
by Mark
Klaus,
Lets not confuse the others. It works correctly now, right?
Mark
Re: get unique values from text
Posted: Thu Dec 20, 2012 2:19 pm
by Klaus
Yes!

Re: get unique values from text
Posted: Thu Dec 20, 2012 2:21 pm
by Mark
Great
