Hello ,
I am doing a program now , and I got a string like that.
string s="123\n~~~\n456\n~~~\n789\n~~~";
I want to do that if the user will insert 456 for example ,
it will delete it from my string .
like , if he will insert 456, so the variable s will contain
123\n~~~\n789\n~~~\n
and if he will insert 123 so the variable s will contain
456\n~~~\n789\n~~~\n
how do I do it? which functions of the string class I need to use ?
erase(x,y) actualy erases y characters starting at position x, not from position x to position y.
In the first example (where x=start of string) these are the same, but in the second it finds the position of "MyCoolNumbers" as the starting point, and then uses the position of the first "~~" as the count.
you want to use
1 2 3
int start = s.find("MyCoolNumbers");
int count = s.find(("~~",start)-start;
s.erase(start , count);
Note that in a more generic case you would want to check start >=0 and count >0 to ensure you had a range to delete.
Hi,
I am Rammohan from Bangalore and working as a Technical lead in big IT firm . Solution for your answer is follows:
I believe I have already explained you in a mail how to do this…
Any way, you can use something like that:
string str = "123\n~~~\n456\n~~~\n789\n~~~";
str.erase(s.find("456") , str.find("~~"));
____________________
Regards, Rammohan Alampally, [email protected]
Technical Lead,
Bangalore, India.
www.FindSyntax.com -> Worlds first Web based Windows O/S is a Brain Chaild of Rammohan