Skip to main content
Inspiring
August 19, 2010
Answered

Compare 2 strings for similar items

  • August 19, 2010
  • 1 reply
  • 568 views

I have 2 strings  --String A and String B

String A  (1,2,3,4,5,6,7,8)

String B (1,2,3,4,9,10,11,12)

I need to compare the 2 strings and find the values that ARE IN BOTH strings.

So the answer I need to get is 1,2,3,4 as 1,2,3,4 is in BOTH strings.

I cant find anything in the CF String Functions.

Any Ideas?

    This topic has been closed for replies.
    Correct answer -__cfSearching__-

    There are different ways to slice it. But a general approach is to loop through one of the lists. Then for each element, use list functions (ie listFindNoCase, etcetera) to determine if it exists in the other list as well. If it does, append the value to a variable. At the end of the loop, you will have a list of elements contained in both lists.

    Having said that, cflib.org is always a good place to check first.

    http://cflib.org/udf/ListInCommon

    1 reply

    -__cfSearching__-Correct answer
    Inspiring
    August 19, 2010

    There are different ways to slice it. But a general approach is to loop through one of the lists. Then for each element, use list functions (ie listFindNoCase, etcetera) to determine if it exists in the other list as well. If it does, append the value to a variable. At the end of the loop, you will have a list of elements contained in both lists.

    Having said that, cflib.org is always a good place to check first.

    http://cflib.org/udf/ListInCommon