-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsString.h
275 lines (268 loc) · 5.46 KB
/
clsString.h
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#pragma once
#include<iostream>
#include <vector>
using namespace std;
class clsString
{
private:
string _Value;
public:
clsString()
{
_Value = "";
}
clsString(string Value)
{
_Value = Value;
}
void SetString(string Value)
{
_Value = Value;
}
string GetString()
{
return _Value;
}
__declspec(property(put = SetString, get = GetString)) string Value;
static int CountWordsInString(string S1)
{
string delim = " "; // delimiter
short pos = 0;
string sWord; // define a string variable
int Counter = 0;
// use find() function to get the position of the delimiters
while ((pos = S1.find(delim)) != std::string::npos)
{
sWord = S1.substr(0, pos);
if (sWord != "")
{
Counter++;
}
S1.erase(0, pos + delim.length());
}
if (S1 != "")
{
Counter++;
}
return Counter;
}
int CountWordsInString()
{
return CountWordsInString(_Value);
}
static string UpperAllLetters(string YourString)
{
for (int i = 0; i < YourString.length(); i++)
{
YourString[i] = toupper(YourString[i]);
}
return YourString;
}
string UpperAllLetters()
{
return UpperAllLetters(_Value);
}
static string LowerAllLetters(string YourString)
{
for (int i = 0; i < YourString.length(); i++)
{
YourString[i] = tolower(YourString[i]);
}
return YourString;
}
string LowerAllLetters()
{
return LowerAllLetters(_Value);
}
static short CountCapitalLetters(string& ReadString)
{
short Count = 0;
for (short i = 0; i < ReadString.length(); i++)
{
if (ReadString[i] != ' ')
{
if (isupper(ReadString[i]))
{
Count++;
}
}
}
return Count;
}
short CountCapitalLetters()
{
return CountCapitalLetters(_Value);
}
static short CountSmallLetters(string& ReadString)
{
short Count = 0;
for (short i = 0; i < ReadString.length(); i++)
{
if (ReadString[i] != ' ')
{
if (islower(ReadString[i]))
{
Count++;
}
}
}
return Count;
}
short CountSmallLetters()
{
return CountSmallLetters(_Value);
}
static int CountCharacterRepetition(string& UserString, char& Letter)
{
int Counter = 0;
for (char& L : UserString)
{
if (Letter == L)
Counter++;
}
return Counter;
}
int CountCharacterRepetition(char Letter)
{
return CountCharacterRepetition(_Value, Letter);
}
static bool CheckTheLetterIsVowel(char Letter)
{
Letter = tolower(Letter);
return ((Letter == 'a') || (Letter == 'e') || (Letter == 'i') || (Letter == 'o') || (Letter == 'u'));
}
static int CountVowelNumbersInString(string StringFromUser)
{
int Counter = 0;
for (char& L : StringFromUser)
{
if (CheckTheLetterIsVowel(L))
Counter++;
}
return Counter;
}
int CountVowelNumbersInString()
{
return CountVowelNumbersInString(_Value);
}
static void PrintVowelLettersInString(string StringFromUser)
{
int Counter = 0;
for (char& L : StringFromUser)
{
if (CheckTheLetterIsVowel(L))
cout << " " << L;
}
}
void PrintVowelLettersInString()
{
PrintVowelLettersInString(_Value);
}
static void PrintEachWordInString(string S1)
{
string delim = " "; // delimiter
cout << "\nYour string wrords are: \n\n";
short pos = 0;
string sWord; // define a string variable
// use find() function to get the position of the delimiters
while ((pos = S1.find(delim)) != std::string::npos)
{
sWord = S1.substr(0, pos); // store the word
if (sWord != "")
{
cout << sWord << endl;
}
S1.erase(0, pos + delim.length()); /* erase() until
positon and move to next word. */
}
if (S1 != "")
{
cout << S1 << endl; // it print last word of the string.
}
}
void PrintEachWordInString()
{
PrintEachWordInString(_Value);
}
static vector <string> SplitString(string S1, string delim)
{
vector <string> vTokens;
short pos = 0;
string sWord; // define a string variable
// use find() function to get the position of the delimiters
while ((pos = S1.find(delim)) != std::string::npos)
{
sWord = S1.substr(0, pos);
if (sWord != "")
{
vTokens.push_back(sWord);
}
S1.erase(0, pos + delim.length());
}
if (S1 != "")
{
vTokens.push_back(S1);
}
return vTokens;
}
vector <string> SplitString(string delim)
{
return SplitString(_Value,delim);
}
static string JoinString(vector <string> Names, string Delim)
{
string FullName = "";
for (string& name : Names)
{
FullName = FullName + name + Delim;
}
return FullName;
}
static string ReverseString(string UserString)
{
string Words = "";
for (short i = UserString.length() - 1; i >= 0; i--)
{
if (UserString[i] == ' ')
{
Words = Words + UserString.substr(i + 1, UserString.length()) + " ";
UserString.erase(i, UserString.length());
}
}
return Words + UserString;
}
string ReverseString()
{
return ReverseString(_Value);
}
static string ReplaceWordsInString(string UserString, string word1, string word2)
{
short pos = UserString.find(word1);
while (pos != std::string::npos)
{
UserString = UserString.replace(pos, word1.length(), word2);
pos = UserString.find(word1);
}
return UserString;
}
string ReplaceWordsInString(string word1, string word2)
{
return ReplaceWordsInString(_Value, word1, word2);
}
static string RemovePunctuationCharacters(string Words)
{
string RemovePunctuation = "";
for (short i = 0; i < Words.length(); i++)
{
if (!ispunct(Words[i]))
{
RemovePunctuation += Words[i];
}
}
return RemovePunctuation;
}
string RemovePunctuationCharacters()
{
return RemovePunctuationCharacters(_Value);
}
};