Advertisement
Naohiro19

Alphabet upper case with std::regex

Jan 28th, 2019
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. struct Replacement {
  9.     string Before;
  10.     string After;
  11.     Replacement(string Before, string After)
  12.         : Before(Before), After(After) {}
  13. };
  14.  
  15. int main()
  16. {
  17.     vector<Replacement> rep = {
  18.         {"a", "A"},{"b", "B"},{"c", "C"},{"d", "D"},
  19.         {"e", "E"},{"f", "F"},{"g", "G"},{"h", "H"},
  20.         {"i", "I"},{"j", "J"},{"k", "K"},{"l", "L"},
  21.         {"m", "M"},{"n", "N"},{"o", "O"},{"p", "P"},
  22.         {"q", "Q"},{"r", "R"},{"s", "S"},{"t", "T"},
  23.         {"u", "U"},{"v", "V"},{"w", "W"},{"x", "X"},
  24.         {"y", "Y"},{"z", "Z"}
  25.     };
  26.  
  27.     string str = "hello my name is...";
  28.  
  29.     for(const Replacement repl: rep)
  30.     {
  31.         regex rx(repl.Before);
  32.         str = regex_replace(str, rx, repl.After);
  33.     }
  34.  
  35.     cout << str << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement