-
Notifications
You must be signed in to change notification settings - Fork 0
/
015-Strings.cpp
50 lines (37 loc) · 999 Bytes
/
015-Strings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s1;
int pos, n;
char ch;
cin >> s;
cout << "1: To insert a sub-string in to given main string from a given position." << endl <<
"2: To delete n Characters from a given position in a given string." << endl <<
"3: To replace a character of string either from beginning or ending or at a specified location." << endl;
int choice;
cin >> choice;
switch(choice) {
case 1:
cout << "Enter Pos: ";
cin >> pos;
cout << "Enter new string: ";
cin >> s1;
s = s.substr(0, pos) + s1 + s.substr(pos, s.length()-1);
break;
case 2:
cout << "Enter number of char to delete and Pos: ";
cin >> n >> pos;
s = s.substr(0, pos) + s.substr(pos+n, s.length()-1);
break;
case 3:
cout << "Enter Pos: ";
cin >> pos;
cout << "Enter character: ";
cin >> ch;
if(pos > -1 && pos < s.length())
s[pos-1] = ch;
break;
}
cout << s << endl;
return 0;
}