0% found this document useful (0 votes)
17 views3 pages

Cse Lab C3

The document contains C++ code snippets that demonstrate string manipulation functions including substring extraction, insertion, deletion, and replacement. Each section provides a specific function to modify a string based on given parameters. The main function in each section tests these string manipulation functions with example strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Cse Lab C3

The document contains C++ code snippets that demonstrate string manipulation functions including substring extraction, insertion, deletion, and replacement. Each section provides a specific function to modify a string based on given parameters. The main function in each section tests these string manipulation functions with example strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

using namespace std;


string mysub(string s, int pos,int len)
{
string result="";
for(int i=pos;i<pos+len;i++){
result+=s[i];
}
return result;
}

int main()

{
string s="some text";
cout<<mysub(s,3,6);
}

Insertion

#include<iostream>
using namespace std;
string mysub(string s, int pos,int len)
{
string result="";
for(int i=pos;i<pos+len;i++)
{
result+=s[i];
}
return result;
}
string insertion(string s, int pos, string p)
{
return mysub(s,0,pos)+ p + mysub(s,pos,s.size()-pos);

int main(){

string s="some text";

cout<<insertion(s,5,"new");
}
Deletion

#include<iostream>
using namespace std;
string mysub(string s, int pos,int len)
{
string result="";
for(int i=pos;i<pos+len;i++)
{
result+=s[i];
}
return result;
}
string insertion(string s, int pos, string p)
{
return mysub(s,0,pos)+ p + mysub(s,pos,s.size()-pos);

}
string deletion(string s, int pos, int len)
{
return mysub(s,0,pos) + mysub(s,pos+len, s.size()-pos-len);
}
int main(){

string s="ABCDXYZDEF";

cout<<deletion(s,4,4);
}
REPLACE

#include<iostream>
using namespace std;
string mysub(string s, int pos,int len)
{
string result="";
for(int i=pos;i<pos+len;i++)
{
result+=s[i];
}
return result;
}
string insertion(string s, int pos, string p)
{
return mysub(s,0,pos)+ p + mysub(s,pos,s.size()-pos);

}
string deletion(string s, int pos, int len)
{
return mysub(s,0,pos) + mysub(s,pos+len, s.size()-pos-len);
}
string replacement(string s,string p1,string p2){
int pos=s.find(p1);

s= deletion(s,pos,p1.size());
s= insertion(s,pos,p2);
return s;
}
int main(){

string s="ABCDOOOEF";

cout<<replacement(s,"OOO","XYZ");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy