Finds all strings in an array that match a given test string. The test string may contain wild characters * and ?.
int okutil_find_strings( StringArray * psaFound, StringArray * psaSearch, LPCSTR lpszFindThis, DWORD dwOptions = OFS_MATCH_WHOLE_STRING, IntArray* pnIndex = NULL )
the number of matches found.
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]); } }
origin.h