use regex to turn things like: LE471611-10 UK LE471611-10.5 UK LE471611-11 UK LE471611-11.5 UK LE471611-12 UK LE471611-12.5 UK LE471611-13 UK LE471611-13.5 UK LE471611-5.5 UK LE471611-6 UK to: LE471611-100UK LE471611-105UK LE471611-110UK LE471611-115UK LE471611-120UK LE471611-125UK LE471611-130UK LE471611-135UK LE471611-055UK LE471611-060UK
#include <iostream> #include <regex> using namespace std; // gcc -std=c++11 -o regex_test regex_test.cpp int main() { regex re("(.*)(-)(.*)(UK)"); string s = "LE471611-10 UK"; cout << regex_replace(s, re, "$100$4") << '\n'; return 0; }