-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-utility.cpp
More file actions
46 lines (38 loc) · 900 Bytes
/
string-utility.cpp
File metadata and controls
46 lines (38 loc) · 900 Bytes
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
#include "string-utility.h"
void removeBrackets(string& s)
{
size_t found1 = s.find_first_of("(");
size_t found2 = s.find_first_of(")");
while (found1!=string::npos){
s.erase(found1,1);
found1 = s.find_first_of("(");
}
while (found2!=string::npos){
s.erase(found2,1);
found2 = s.find_first_of(")");
}
}
void removeCommas(string& s)
{
size_t found = s.find_first_of(",");
while (found!=string::npos){
s.erase(found,1);
found = s.find_first_of(",");
}
}
void removeBlanksandOther(string& s)
{
size_t found = s.find_first_of(" ");
while (found!=string::npos){
s.erase(found,1);
found = s.find_first_of(" ");
}
removeBrackets(s);
removeCommas(s);
}
int str2int(const string &s) {// convert string in number
istringstream itmp(s);
int n;
itmp >> n;
return n;
}