Manipulation of string object:- With the help of different member functions of string class we can modify or manipulate value of string object. In following example we are displaying some manipulating function e.g. insert( ), erase( ), replace( ), appeal( ).
C++ program to display manipulation of string.
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main(){
string s1("abcde"),s2("12345");
cout<<"Original strings are "<<endl<<"S1= "<<s1<<endl<<"S2= "<<s2<<endl;
getch();
cout<<"Insert function"<<endl;
s1.insert(4,s2);
cout<<"S1= "<<s1<<endl;
//s1=abcd12345e
getch();
cout<<"Erase function"<<endl;
s1.erase(4,2);
cout<<"S1= "<<s1<<endl;
//s1=abcd345e
getch();
cout<<"Replace function"<<endl;
s1.replace(1,4,"wxyz");
cout<<"S1= "<<s1<<endl;
//s1=wxyz345e
getch();
cout<<"Append function"<<endl;
s1.append("shiv");
cout<<"S1= "<<s1<<endl;
//s1=wxyz345eshiv
getch();
}
No comments:
Post a Comment