blob: 48bbc467a7dabf974c66130386faa252abdae0e5 (
plain)
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
|
using namespace std;
//replace all "search" with "replace" in "subject"
string str_replace(const string& search, const string& replace, const string& subject) {
string str = subject;
size_t pos = 0;
while((pos = str.find(search, pos)) != string::npos) {
str.replace(pos, search.length(), replace);
pos += replace.length();
}
return str;
}
//cut string after first "search"
string str_cut(const string& search, const string& subject) {
string str = subject;
string strCutted = "";
size_t found = str.find_first_of(search);
if (found != string::npos) {
strCutted = str.substr(0, found);
size_t foundSpace = strCutted.find_last_of(" ");
if ((foundSpace != string::npos) && (foundSpace == (strCutted.size()-1))) {
strCutted = strCutted.substr(0, strCutted.size()-1);
}
}
return strCutted;
}
|