2.1.2.40 remove_if_not_in_list


Description

Filter a vector of strings by another , remove all those elements that are not in the second list

Syntax

int remove_if_not_in_list( vector<string> & vsToCheck, const vector<string> & vsList, bool bCaseSensitive = false )

Parameters

vsToCheck
[modify] the string array to be checked and removed items.
vsList
[input] the reference string array.
bCaseSensitive
[input] true to make the comparing case sensitive.

Return

number of elements removed.

Examples

EX1

void remove_if_not_in_list_ex1()
{
    vector<string> vsToCheck = {"Hello","hi","Sorry","oo"};
    vector<string> vsList = {"Hello","hi","FT","Ex","oo"};
    bool bCaseSensitive = true;
    int nRet = remove_if_not_in_list(vsToCheck,vsList,bCaseSensitive);
    if(nRet)
    {	
		printf("element deleted number is %d \n" ,nRet);
		//Should print "Hello hi oo "
		for(int ii=0; ii<vsToCheck.GetSize(); ii++)
		printf("%s ",vsToCheck[ii]);
    }
    else
    printf("remove failed\n");
}

Remark

See Also

remove_if_in_list

Header to Include

origin.h

Reference