I want to loop through a comma separated list of numbers to see which is present in a string, here is a very simplified version of what I want to do:
<script runat="server" language="ampscript"> VAR @string, @numbers SET @string = "munksgaard#13" SET @numbers = "11,12,13,14" IF IndexOf(@string, "11") != 0 THEN SET @numberfound = "11" ELSEIF IndexOf(@string, "12") != 0 THEN SET @numberfound = "12" ELSEIF IndexOf(@string, "13") != 0 THEN SET @numberfound = "13" ELSEIF IndexOf(@string, "14") != 0 THEN SET @numberfound = "14" ELSE SET @numberfound = "notfound" ENDIF </script> @string: %%=v(@string)=%%<br> @numbers: %%=v(@numbers)=%%<br> @numberfound: %%=v(@numberfound)=%%<br>
So, in this example I find the number 13 present in the string.
First of all, I'm not a programmer, so I am aware that my AMPScript is not very good, especially my IF ELSE approach as it isn't easily scalable.
Second of all, the above is just an example. When I need to finish this project I'd have to handle much more complex strings and search for many more numbers, I would have a string and a comma separated list of numbers like this:
**SET @string = "586136#outlet;586476#outlet-dametøj;623741#forår/sommer;586802#bluser, toppe & t-shirts;"** **SET @numbers = "601292,601443,601441,601440,601444,619575,601442,632938,629574,614516,620205,587712,587649,586476,586477,586478"**
Can anyone help me with AMPScript for a proper approach on how to loop through a list of numbers in a string like the one above?