193030

Get only numbers from string

Feb 21st, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. string ns;
  5. strRemove(string s)
  6. {
  7.     for(int i =0; i<s.length(); i++){
  8.             if(s.at(i)>='0' && s.at(i)<='9')
  9.             {
  10.                 ns+=s.at(i);
  11.             }
  12.  
  13.     }
  14. }
  15. using namespace std;
  16. int main()
  17. {
  18.  
  19.    string str1 = "1lore2m ip4um";
  20.    strRemove(str1);
  21.    cout << ns;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment