Home | Develop | Download | Contact
example_ra_string_naturalsorting.cpp
1
20#include <iostream>
21#include <Pds/Ra>
22#include <algorithm>
23
24int main(void)
25{
26 std::map<std::string,std::string,Pds::Ra::Sort::NaturalStdString> d;
27
28 d["d1"]="data1";
29 d["d2"]="data2";
30 d["d5"]="data5";
31 d["d7"]="data7";
32 d["d10"]="data10";
33 d["d11"]="data11";
34
35 std::map<std::string,std::string>::iterator it;
36
37 for(it=d.begin();it != d.end();it++)
38 std::cout<<it->first<<"\t"<<it->second<<"\n";
39
40 std::vector<std::string> vec={"d1","d10","d11","d7","d2","d5"};
41
42 std::sort(vec.begin(), vec.end(), Pds::Ra::NaturalCompare);
43
44 for(unsigned int n=0;n<vec.size();n++)
45 std::cout<<vec[n]<<"\n";
46
47 return 0;
48}
bool NaturalCompare(const std::string &str1, const std::string &str2)
Esta función compara las cadenas str1 y str2 de forma natural (tomando en cuenta números).

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed