How to remove duplicate symbol from string list

Hi,

how to remove duplicate symbol from list.

sym_dup_list = "ACC,ASIANPAINT,ADANIENT,ADANIPORTS,ALKEM,ACC,AMARAJABAT,ADANIPORTS,AMBUJACEM,APLLTD,ALKEM,APOLLOHOSP,ADANIPORTS,APOLLOHOSP,APOLLOTYRE,ASHOKLEY,ASIANPAINT";

i expecting output as per below

sym_list = "ACC,ASIANPAINT,ADANIENT,ADANIPORTS,ALKEM,AMARAJABAT,AMBUJACEM,APLLTD,APOLLOHOSP,APOLLOTYRE,ASHOKLEY";

This can be done in many ways, but the simplest is just to build new list without duplicates:

sym_dup_list = "ACC,ASIANPAINT,ADANIENT,ADANIPORTS,ALKEM,ACC,AMARAJABAT,ADANIPORTS,AMBUJACEM,APLLTD,ALKEM,APOLLOHOSP,ADANIPORTS,APOLLOHOSP,APOLLOTYRE,ASHOKLEY,ASIANPAINT";

sym_list = "";
for( i = 0; ( sym = StrExtract( sym_dup_list, i ) ) != ""; i++ )
{ 
  sym += ","; // append separator
  if( StrFind( sym_list, sym ) == 0 )
  {
   // not found -> add to the list
   sym_list += sym;
  }
}

sym_list = StrTrim( sym_list, ",", 2 ); // trim separator at the end
2 Likes

Hi Tomasz,

Thank you for given solution. :slightly_smiling_face:

one more doubt, duplicate sym list removed and then how to sorting a to z alphabet list.

Does it hurt you to use GOOGLE? Type amibroker string sort into Google amibroker string sort - Google Search

First hit in Google search result is this: AFL Function Reference - STRSORT

As you can see sorting of list of strings is a built-in function.

1 Like

Hi Tomasz,

mostly i am using library, today i think missed that contend suddenly. henceforth i will check it library before post if any difficult to solve.

thanks for guide.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.