-
Notifications
You must be signed in to change notification settings - Fork 61
/
stringOperations.cpp
60 lines (48 loc) · 1.52 KB
/
stringOperations.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
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
int main()
{
// string x;
// cin >> x;
// cout << x << endl;
// // declare using size and specified char
// string str1(5, 'n');
// cant have space
// input it with spaces
string str = "name";
string spaces;
// getline(cin, spaces);
// cout << spaces << endl;
string str1 = "fam", str2 = "ily";
// str1.append(str2); // str1 = str1 + str2;
cout << str1 + str2 << endl; // concat
cout << str1[1] << endl; // access
string abc = "asdsfbdfbddvqefiefpbsbdviaia";
abc.clear(); // CLEAR THE WHOLE STRING
cout << abc << endl;
string _1 = "abc";
string _2 = "xyz";
cout << _2.compare(_1) << endl; // ascii value
// 0 means same, +ve is 2 bigger, -ve is 2 smaller
// empty() to check if empty
// !empty() to make sure string not empty()
// erase() function
// s1.erase(3,3); start index and chars to delete
// find() to find if substring is part of string
// s1.find("com") // returns first index where it finds
// s1.insert(2,"lol") // index and string to insert
// s1.length()/ s1.size() // returns size of string
// s1.substr(6,4) // index and no of chars need
string num = "786";
// string to integers
int x = stoi(num);
cout << x + 1 << endl;
// integer to string
int y = 789;
cout << to_string(y) + "2" << endl;
// sorting a string
string uwu = "xadinfeodvgdsvvvvbdcqb";
sort(uwu.begin(), uwu.end());
cout << uwu << endl;
return 0;
}