c++ - How to compare 2 QStringList's and show the results? -
i want know how can compare 2 qstringlist
, display results in next way:
i have 2 qplaintextedit
, b
what want this: take each line in b , compare lines in a. if, in 1 line-line comparison, 6 equal int n6 (for example) add together 1. if 5 equal, int n5 add together 1 , on.
i've tried few things none of them worked. if give lite on i'll appreciate.
start calculating number of matching digits per string
int matchingdigits(qstring str1, qstring str2) { int matches = 0; int minsize = str1.size() < str2.size() ? str1.size() : srt2.size(); (int pos = 0; pos < minsize; ++pos) { if (str1.at(pos) == str2.at(pos) ++matches; } homecoming matches; }
now compare strings each other (iterating on both stringlists) , if matchingdigits()
> 0
can increment result counters.
qstringlist lista; qstringlist listb; foreach (qstring a, lista) { foreach (qstring b, listb) { int matches = matchingdigits(a, b); if (matches > 0) { // fancy } } }
c++ qt
No comments:
Post a Comment