C++ (Qt)Zombie_Hip Zombie_RightLeg Zombie_LeftArm ..// префикс Zombie_
C++ (Qt)#include <iostream>#include <vector>#include <algorithm> std::vector<std::string> strings; strings.push_back("Zombie_Hip"); strings.push_back("Zombie_RightLeg"); strings.push_back("Zombie_LeftArm"); bool all = std::all_of(strings.begin(), strings.end(), [](std::string str){ return str.find("Zombie_") == 0; }); std::cout << all; // 1 strings.push_back("Vasya_LeftArm"); all = std::all_of(strings.begin(), strings.end(), [](std::string str){ return str.find("Zombie_") == 0; }); std::cout << '\n'; std::cout << all; // 0
C++ (Qt)bool my_all_of(const std::vector<std::string>& strings, const std::string& prefix) { for (std::string text: strings) { if (text.find(prefix) != 0) { return false; } } return true;}
C++ (Qt)bool TestMatch( std::string & src0, const std::string & src1 ){// find matched strings start size_t len, maxLen = qMin(src0.size(), src1.size()); for (len = 0; len < maxLen; ++len) if (src0[len] != src1[len]) break; src0.resize(len); // src0 end can't be a letter or digit while (src0.size()) { size_t last = src0.size() - 1; QChar ch = src0[last]; if (ch.isLetter() || ch.isDigit()) src0.resize(last); else break; } return src0.size() > 0;}
C++ (Qt)std::string GetPrefix( const std::vector<std::string> & vec ){ if (vec.size() < 2) return std::string(); std::string match = vec[0]; // копируем первую строку for (size_t i = 1; i < vec.size(); ++i) if (!TestMatch(match, vec[i])) break; return march;}