find_in_list

 

Description

Look for the given double value in list of numeric values.


Look for the given int value is in list of int values.


Look for the given text if can be found in list of text separated with separator.

Syntax

string find_in_list( double dVal, const string & strList, char cSeparator = '|' )

int find_in_list( int nVal, const vector<int> & vn, bool bWasSortedAccending )

int find_in_list(LPCSTR lpcszVal, LPCSTR lpcszList, char cSeparator = '|', bool bCaseSensitive = true)

Parameters

dVal
[input] numeric value to look for
strList
[input] a string that has a list of numbers separated by a cSeparator
cSeparator
[input] the charactor to separate these values

nVal
[input] int value to look for
vn
[input] a vector containing int values
bWasSortedAccending
[input] indicate whether vn was sorted assending

lpcszVal
[input] the text to look for
lpcszList
[input] a text containing multiple sub text separated by separator.
cSeparator
[input] the charactor to separate these sub text.
bCaseSensitive
[input] true if string comparison is case sensitive

Return

numeric string in the list if found, or an empty string if not.


index into vn if found, or -1 if not.


index if test can be found in text list, or -1 if not.

Examples

EX1

void find_in_list_ex1()
{
    string strList = "1,2,3,3.4,4,4.23,5";
    string str = find_in_list(3.4, strList, ',');
    out_str(str);            
}

EX2

void find_in_list_ex2()
{
        int nVal = 3;
    vector<int>    vnList = {1,2,3,4,5};
    bool bWasSortedAccending = true;
    
    int ret = find_in_list(nVal, vnList, bWasSortedAccending);  
    // should return 2, the index of nVal in vnList
    printf("ret is %d\n",ret);    
}

Remark

See Also

is_in_list

header to Include

origin.h

Reference