2.1.2.36 okutil_find_strings


Description

Finds all strings in an array that match a given test string. The test string may contain wild characters * and ?.

Syntax

int okutil_find_strings( StringArray * psaFound, StringArray * psaSearch, LPCSTR lpszFindThis, DWORD dwOptions = OFS_MATCH_WHOLE_STRING, IntArray* pnIndex = NULL )

Parameters

psaFound
[output] an array containing strings from the original array that match the test string lpszFindThis. Can be NULL if you want just the number of matches.
psaSearch
[output] the array of strings to be searched.
lpszFindThis
[input] the test string to find. It may contain wild characters * and ?.
dwOptions
[input] Can be 0x0, or you can 'OR' together any of the following:
OFS_CASE_SENSITIVE the match must be case sensitive
OFS_WILDCHARS_OFF interpret wild characters * and ? as literals, not wild characters.
OFS_MATCH_START_STRING the test string must match the beginning of the searched string. If there are wild characters (and OFS_WILDCHARS_OFF is not set), then OFS_MATCH_START_STRING has no affect.
OFS_MATCH_WHOLE_STRING the test string must equal the searched string (up to case, which is controlled by OFS_CASE_SENSITIVE). If there are wild characters (and OFS_WILDCHARS_OFF is not set), then OFS_MATCH_START_STRING has no affect.
pnIndex
[output] an array containing item indices of the original array that match the test string lpszFindThis. Can be NULL.

Return

the number of matches found.

Examples

EX1

void okutil_find_strings_Ex1()
{
    StringArray saSearch;
    StringArray saFound;
    
    saSearch.Add("abc");
    saSearch.Add("azc");
    saSearch.Add("abc123");        
    saSearch.Add("ab*23");
    saSearch.Add("a?b");
    saSearch.Add("123abc");

    
    DWORD dwOptions = 0x0;
    int nFound = 0;
    int ii=0;
    
    string strFind = "abc";
    nFound = okutil_find_strings(&saFound, &saSearch, strFind);// dwOptions=OFS_MATCH_WHOLE_STRING by default
    out_str("A; match(s) to abc found:(OFS_MATCH_WHOLE_STRING)");
    for(ii=0; ii<nFound; ii++)
    {
        
        out_str(saFound[ii]);
    }
    
    strFind = "b*";
    nFound = okutil_find_strings(&saFound, &saSearch, strFind, dwOptions);
    out_str("D: match(s) to b* found:(* is wild)");
    for(ii=0; ii<nFound; ii++)
    {
        out_str(saFound[ii]);
    }
    
    strFind = "*b*";
    nFound = okutil_find_strings(&saFound, &saSearch, strFind, dwOptions);
    out_str("C: match(s) to *b* found:(* is wild)");
    for(ii=0; ii<nFound; ii++)
    {        
        out_str(saFound[ii]);
    }

    dwOptions =  OFS_WILDCHARS_OFF;
    strFind = "b*";
    nFound = okutil_find_strings(&saFound, &saSearch, strFind, dwOptions);
    out_str("D: match(s) to *b* found: (OFS_WILDCHARS_OFF so * is literal)");
    for(ii=0; ii<nFound; ii++)
    {
        out_str(saFound[ii]);
    }
    
    dwOptions =  0x0;
    strFind = "123";
    nFound = okutil_find_strings(&saFound, &saSearch, strFind, dwOptions);
    out_str("E: match(s) to 123 found: (no condition...match anything)");
    for(ii=0; ii<nFound; ii++)
    {
        out_str(saFound[ii]);
    }

    dwOptions =  OFS_MATCH_START_STRING;
    strFind = "123";
    nFound = okutil_find_strings(&saFound, &saSearch, strFind, dwOptions);
    out_str("F: match(s) to 123 found: (OFS_MATCH_START_STRING)");
    for(ii=0; ii<nFound; ii++)
    {
        out_str(saFound[ii]);
    }
}

Remark

See Also

Header to Include

origin.h

Reference