0

Hi I have a string variable with large content. I have to remove unwanted line from the string content and keep remaining content as it is. Following is output that we get after printing the string:

string varString;
cout<<"String content :"<<endl<<varString<<endl;

Output is :
String content :
/abc/def/ghi/klm/run.so
call::myFuncton(int const&)
call::MY::Method(char const&)
.
.
.
call::MY::newFunction(char *&)

Now i have to remove "call::myFuncton(int const&)" line from above string variable and keep other data as it is. can any one tell tell me how i can remove that line from sting variable? Thanks in advance

BSalunke
  • 11,499
  • 8
  • 34
  • 68

3 Answers3

2

You can use the function varString.find() to find the position where the string occurs, and then use varString.erase() to erase the text.

Jan S
  • 1,831
  • 15
  • 21
1

You first find the string then you erase it.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
0

You can use Regex to replace the required string call::myFuncton(int const&) using Regex. You can find more information about using Regex in C++ from this link C++: what regex library should I use?

Community
  • 1
  • 1
Srinivas
  • 1,780
  • 1
  • 14
  • 27
  • This approach is beneficial if you intend to remove all **call:Func(param)** strings from your single big block of string, otherwise [find](http://www.cplusplus.com/reference/string/string/find/) and [erase](http://www.cplusplus.com/reference/string/string/erase/) should work out pretty well. – Srinivas Oct 13 '11 at 05:28