Advertisement
193030

C++ spaceSearching and StrRemove

Feb 22nd, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7.     string ns;
  8.  
  9. strRemove(string s)
  10. {
  11.     for(int i =0; i<s.length(); i++){
  12.             if(s.at(i)!=' ')
  13.             {
  14.                 ns+=s.at(i);
  15.             }
  16.  
  17.     }
  18.  
  19. }
  20. stringSpace(string inputString, int spaceNumber)
  21. {
  22.    int found = -1;
  23.    int lookedSpace = 0;
  24.    int counter = 0;
  25.    do
  26.    {
  27.        found = inputString.find(" ", found+1);
  28.        if(found!=-1)
  29.        {
  30.            lookedSpace = found;
  31.            counter++;
  32.        }
  33.    }
  34.   // while(found<=words.length()-15);
  35.       while(counter<spaceNumber);
  36.       return lookedSpace;
  37.  
  38. }
  39.  
  40.  int main()
  41. {
  42.  
  43.    string words = "one two three four five six";
  44.    string word = "zero";
  45.   /* int found = -1;
  46.    int lastSpace = 0;
  47.    int counter = 0;
  48.    do
  49.    {
  50.        found = words.find(" ", found+1);
  51.        if(found!=-1)
  52.        {
  53.            lastSpace = found;
  54.            counter++;
  55.        }
  56.    }
  57.   // while(found<=words.length()-15);
  58.       while(counter<2);
  59.     */
  60.    //words = words.substr(0,found) + " "+ word +words.substr(found);
  61.  
  62.    //words = words.substr(0,lastSpace) + " "+ word +words.substr(lastSpace);
  63.    int spaceFound = stringSpace(words,1);
  64.   // int spaceFound1 = stringSpace(words,1);
  65.    //int spaceFound2 = stringSpace(words,3);
  66.    words = words.substr(0,spaceFound);
  67.    strRemove(words);
  68.    string outputString = ns; // The string from STR REMOVE
  69.     //words = words.substr(spaceFound1,spaceFound2);
  70.    cout << outputString;
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement