summaryrefslogtreecommitdiff
path: root/tools/stringhelpers.c
blob: 2eb3c8caef8407fd0ffa4d808cd4be780f700d59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
    size_t found = str.find_first_of(search);
    if (found != string::npos) {
        return str.substr(0, found);
    }
    return "";
}