Hello,
I am looking for forum assistance in developing File/String Compare function.
I am downloading data from mutual fund source using a list of tickers.
Every now and then, CSV list of funds changes. They may remove or add new fund.
StringCompare() function will be ideal but, I could not find this functionality in AB documentation.
The function needs to compare two lists of tickers (current against previous - last week's CSV)
and identify ticker list difference.
With the help of @PanoS (another very generous forum member) we tried the following idea;
// this code use StrMatch() and it is not good for comparing two lists
GuiButton( "Set_Static_List", 5, 10, 110, 95, 24, 1);
id = GuiGetEvent( 0, 0 ); event = GuiGetEvent( 0, 1 ); SetStaticVar=0;
if( id == 5 && event == 1 ) {SetStaticVar=1; GuiSetText("Button clicked",5); }
printf(" LIST1 = %s\n,LIST2 = %s\n", "zz,C,CAT,DD,GE,IBM,INTC,MSFT", "zz,C,CAT,DD,GE,MSFT,Richard" );
if(SetStaticVar)
{
LIST1 = StaticVarSetText( "LIST1", "zz,C,CAT,DD,GE,IBM,INTC,MSFT");
LIST2 = StaticVarSetText( "LIST2","zz,C,CAT,DD,GE,MSFT,Richard");
}
LIST1 = StaticVargetText( "LIST1");
LIST2 = StaticVargetText( "LIST2");
// the idea behind this loop is to remove one by one the elements from the lists.
for( i = 0; ( sym = StrExtract( LIST1, i ) ) != ""; i++ )
{
printf( "ItemList1 %g = %s\n", i, sym );
for( j = 0; ( sym2 = StrExtract( LIST2, j ) ) != ""; j++ )
{
printf( "<b>ItemList2 \t %g = %s </b>\n", j, sym2 );
if( StrMatch( sym, sym2 ) )
{
printf( "StrMatch \t\t" + sym + "-" + sym2 + "\n" );
//if string match, remove the item from the lists
remove1ListItem = StrReplace( LIST1, sym, "" );
StaticVarSetText( "LIST1", remove1ListItem );
remove2ListItem = StrReplace( LIST2, sym2, "" );
StaticVarSetText( "LIST2", remove2ListItem );
break;
}
//else
printf( "else Not-Match \t" + sym + " - " + sym2 + "\n" );
}
}
In the above example we compare two LISTS which are made up from sample ticker lists (LIST1 and LIST2) rather than reading ticker list strings from the CSV files, but the logic is the same.
The AFL code does not produce desired result. In the interpretation window the letter C from INTC is missing (after the loop is finished). We think that this happens because we use StrMatch().
Which function can we use instead ?. Is there a better way to solve this problem - how to compare two lists - since we don't have a native StrCompare() function?
Any help or suggestion will be greatly appreciated.
Kind Regards
Richard