| | |
Having trouble with deleting suffixes and need help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2009
Posts: 10
Reputation:
Solved Threads: 0
i need help with removing "s" and "tion" properly if i want to input "composition" it should leave me with "composi" but it leaves me with "compo" and if i were to enter a word that starts with an s and doesnt end with an s the word would not be shown. on the other hand if i were to start and end a word with s the s at the end would be deleted like it should. help if you can
[CODE]
int main()
{
cout<<"Enter a series of strings.\n";
int end,end2,end3,end4;
string input;
while(cin>>input)
{
end=input.rfind("ing");
if(end>-1)
{
input=input.substr(0,end);
// cout<<input<<"\n";
}
end2=input.rfind("ed");
if (end2>-1)
{
input=input.substr(0,end2);
// cout<<input<<"\n";
}
end3=input.rfind("s");
if (end3>-1)
{
input=input.substr(0,end3);
//cout<<input<<"\n";
}
end4=input.rfind("tion");
//string last_pos=end4.rfind("s");
if(end4>=-1)
{
input=input.substr(0,end4);
// cout<<input<<"\n";
}
cout<<input<<"\n";
}
}
[CODE]
[CODE]
int main()
{
cout<<"Enter a series of strings.\n";
int end,end2,end3,end4;
string input;
while(cin>>input)
{
end=input.rfind("ing");
if(end>-1)
{
input=input.substr(0,end);
// cout<<input<<"\n";
}
end2=input.rfind("ed");
if (end2>-1)
{
input=input.substr(0,end2);
// cout<<input<<"\n";
}
end3=input.rfind("s");
if (end3>-1)
{
input=input.substr(0,end3);
//cout<<input<<"\n";
}
end4=input.rfind("tion");
//string last_pos=end4.rfind("s");
if(end4>=-1)
{
input=input.substr(0,end4);
// cout<<input<<"\n";
}
cout<<input<<"\n";
}
}
[CODE]
•
•
Join Date: Sep 2009
Posts: 19
Reputation:
Solved Threads: 5
0
#2 25 Days Ago
For removing just a single character you could do something like..
C++ Syntax (Toggle Plain Text)
for (int i = 0; i < string.size(); i++) { if (string[i] == 's') continue; else substring += string[i]; }
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
0
#3 25 Days Ago
Close on the code tags. Note the / (slash) on the ending tag:
[code]
// code here
[/code]
You need to find "s" OR find "ing", not both. If you have "standing", you want to end up with "stand", right? So once you find, "ing" and delete it, make sure you do not test for "s".
That'll solve the problem of accidentally finding both, but I think you have another problem. How about a word like "singer"? It has "ing" inside of it, but it doesn't END with it. rfind is going to find it and then you'll delete it. If the "ing" must be at the END, you'll need to add at least one more test before deleting.
[code]
// code here
[/code]
You need to find "s" OR find "ing", not both. If you have "standing", you want to end up with "stand", right? So once you find, "ing" and delete it, make sure you do not test for "s".
C++ Syntax (Toggle Plain Text)
string word = "standing"; bool foundIngPrefix = false; // code if (/* found "ing" prefix */) { // delete "ing" prefix. foundIngPrefix = true; } if (!foundIngPrefix) { // test for and delete "s" if needed. }
That'll solve the problem of accidentally finding both, but I think you have another problem. How about a word like "singer"? It has "ing" inside of it, but it doesn't END with it. rfind is going to find it and then you'll delete it. If the "ing" must be at the END, you'll need to add at least one more test before deleting.
Last edited by VernonDozier; 25 Days Ago at 6:42 pm.
![]() |
Similar Threads
- Hijack This please check (Viruses, Spyware and other Nasties)
- browser hijack (Viruses, Spyware and other Nasties)
- deleting from a database (Java)
- Homepage has been changed to about:blank (Viruses, Spyware and other Nasties)
- I can't remove about:blank (Viruses, Spyware and other Nasties)
- www.lookfor.cc search still buggin me (Viruses, Spyware and other Nasties)
- Help in Getting Rid of Prosearching.com toolbar (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: structures with pointers
- Next Thread: coding help, reverse array, check for palindrome
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






