1

I have an issue with a string variable which unfortunately contains several values(Phone numbers) with ; as the delimiter.

When the string contains several unique numbers it will list them accordingly which is fine, but when the string contains a phone number twice, it will list the number twice too.

I want to remove duplicate phone numbers.
Example: PHONE_NUMBER_LIST = 12345678; 12345678. In this case i want the output to be 12345678

PHONE_NUMBER_LIST = 12345678; 12345678

%%[
SET @rows = BuildRowsetFromString(@PHONE_NUMBER_LIST,";")

for @i = 1 to rowCount(@rows) do

SET @row = row(@rows, @i)
SET @phone_list = field(@row,1)

 ]%%

  <br>%%=v(@phone_list)=%%

    %%[

next @i ]%%

%%[ else ]%%

%%[ endif ]%%

The actual output is:

12345678
12345678

What I want is:
12345678
2

One thing you could try is storing the current phone number at each loop iteration's end to a separate variable/collection, then checking if the phone number already exists in the collection at the next iteration's start.

%%[
set @phone_number_list = "1111111;1111111;1111111;2222222;1111111;3333333"

/* initialize empty collection */
set @phone_number_collection = "" 

set @rows = BuildRowsetFromString(@phone_number_list, ";")

for @i = 1 to RowCount(@rows) do
  set @row = Row(@rows, @i)
  set @phone_number = Field(@row, 1)

  /* wrapped in arbitrary delimiters to ensure unique string */
  set @phone_number_item = Concat("~", @phone_number, "~")

  /* only output if phone number doesn't exist in collection */
  if IndexOf(@phone_number_collection, @phone_number_item) < 1 then
]%%

%%=V(@phone_number)=%%<br>

%%[
  endif

  /* add phone number to collection */
  set @phone_number_collection = Concat(
    @phone_number_collection,
    @phone_number_item
  )

next @i
]%%

Output

1111111
2222222
3333333

1
  • Yes! @MARK G That worked like a charm! Thank you very much!
    – Martin Ho
    Jul 30 '19 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.