mercredi 25 février 2015

how to make use of STL's for better result and performance in this issue

I have some set of strings let say in format : country/currency/minimum_amount ex.


US/USD/18 US/EUR/20 DE/USD/22 GB/EUR/19


let's say i have drop downs each for country, currency and minimum amount. Once i select the country, i should get the possible combination of currency and min amount from the above set of strings.


ex. Once i select country as US in dropdown_1, then currency(dropdown) should display - USD and EUR and min_amt - 18 and 20.\ ex. 2: Once i select Currency as USD in dropdown_2, then country(dropdown) should display - US and DE and min_amt - 18 and 22.. similarly for the third drop down as well.


My solution, Lets assume i have these specific strings in a vector(name - myvector), then I'm retrieving the strings using:



std::string str2("US"); // i need the strings that has country as US
string credt_fin_str;

for (unsigned j=0; j<myvector.size(); j++)
{
credt_fin_str = myvector.at(j);
std::size_t found = credt_fin_str.find(str2);

if(found != string::npos)
{
std::cout<<"creditfin found:"<<credt_fin_str<<std::endl;
}

}


Output :


US/USD/18 US/EUR/20 DE/USD/22


Since i using string::find, it displays even "USD" as it contains "US" but it shouldn't be for my use case.


can anyone suggest a better solution to this use case so that i can improve the result and performance.


Aucun commentaire:

Enregistrer un commentaire