-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.cpp
More file actions
169 lines (144 loc) · 3.33 KB
/
function.cpp
File metadata and controls
169 lines (144 loc) · 3.33 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <iostream>
#include <string>
#include <vector>
#include "function.h"
using namespace std;
string ChangeCase(string word, int pick, bool keepSpace)
{
string text = "";
for (char c : word)
{
if (!keepSpace && c == ' ') continue;
if (pick == 1)
{
if (c >= 'a' && c <= 'z')
{
text += c - 32;
}
else text += c;
}
else if (pick == 2)
{
if (c >= 'A' && c <= 'Z')
{
text += c + 32;
}
else text += c;
}
else if (pick == 3)
{
if (c >= 'a' && c <= 'z')
{
text += c - 32;
}
else if (c >= 'A' && c <= 'Z')
{
text += c + 32;
}
else text += c;
}
}
return text;
}
string revers(string word)
{
string res = "";
for (int i = word.length() - 1; i >= 0; --i)
{
res += word.at(i);
}
return res;
}
string swapChar(string str, char old, char New)
{
string res;
for (char c : str)
{
if (c == old) c = New;
res += c;
}
return res;
}
void swapWord(vector<string>& words, string& old, string& New)
{
for (int i = 0; i < words.size(); ++i)
{
if (words.at(i) == old) words.at(i) = New;
}
}
string trim(string str, char ch, string direction)
{
string res;
int count_left = 0;
int count_right = 0;
for (char c : str)
{
if (c == ch) count_left++;
else break;
}
for (int i = str.length() - 1; i >= 0; --i)
{
if (str.at(i) == ch) count_right++;
else break;
}
if (direction == "left" || direction == "Left" || direction == "1")
{
for (int i = count_left; i < str.length(); ++i)
{
res += str.at(i);
}
}
else if (direction == "right" || direction == "Right" || direction == "2")
{
for (int i = 0; i < str.length() - count_right; ++i)
{
res += str.at(i);
}
}
else if (direction == "all" || direction == "All" || direction == "3")
{
for (int i = count_left; i < str.length() - count_right; ++i)
{
res += str.at(i);
}
}
return res;
}
string cleanString(string str, char ch = ' ', bool keepSpace = true, bool keepSpecialCh = true)
{
string res;
for (int i = 0; i < str.length(); ++i)
{
int index = str.at(i);
if (index >= 'a' && index <= 'z')
{
res += index;
}
else if (index >= 'A' && index <= 'Z')
{
res += index;
}
else if (keepSpace && index == ' ') res += index;
else if (keepSpecialCh && index == ch) res += index;
}
return res;
}
string Zfill(string str, int width, char fill)
{
size_t sizeString = str.size();
if (sizeString < width)
{
for (int i = 0; i < width - sizeString; ++i)
{
str = fill + str;
}
}
return str;
}
void ads()
{
system("start chrome https://www.linkedin.com/in/amrsa3dwy/");
system("start chrome https://github.com/Amr4924");
system("start chrome https://www.facebook.com/profile.php?id=100079413693293");
system("start chrome https://linktr.ee/sa3dwy");
}