Guest User

Print the part of a string after and before a part or sequence

a guest
Jun 11th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool start_with(string start, string s)
  6. {
  7.     if (start.find(s) == 0)
  8.     {
  9.         return true;
  10.     }
  11.     return false;
  12. }
  13.  
  14. int main()
  15. {
  16.     string input;
  17.     cout << "Enter a String with (\" and \"): ";
  18.     cin >> input;
  19.     string startT = "(\"";
  20.     string endT = "\")";
  21.     int startLen = startT.length(); // 2
  22.     int endLen = endT.length();     // 2
  23.     int strLen = input.length();    // if hello => 2+5+2 = 9
  24.     cout << strLen << endl;
  25.     string output = ""; // output = 9 - 2 - 2 => strLen - endLen - startLen
  26.     output = input.substr(startLen, (strLen - endLen - startLen));
  27.     cout << output << endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment