-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStringFuncs.cpp
More file actions
50 lines (47 loc) · 1.05 KB
/
Copy pathStringFuncs.cpp
File metadata and controls
50 lines (47 loc) · 1.05 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
#include "StringFuncs.h"
std::string SeekToPhrase(const std::string &strPhrase, std::istream &iStream)
{
std::string strLine;
std::getline(iStream, strLine);
while(strLine.find(strPhrase) == std::string::npos && !iStream.eof())
{
std::getline(iStream, strLine);
};
return strLine;
}
std::string RemoveWhitespace(const std::string &str)
{
std::string strOut;
for(size_t i = 0; i < str.size(); i++)
{
char c = str[i];
if(c == '\n' || c == '\r' || c == '\x09' || c == ' ')
{
continue;
}
strOut += c;
}
return strOut;
}
std::string StringReplace(std::string str, const std::string &strReplace, const std::string &strWith, unsigned int count)
{
size_t pos = str.find(strReplace);
for(unsigned int i = 0; pos != std::string::npos && (i < count || count == 0); i++)
{
str.replace(pos, strReplace.size(), strWith);
pos = str.find(strReplace);
}
return str;
}
unsigned int CharCount(const std::string &str, const char c)
{
unsigned int count = 0;
for(size_t i = 0; i < str.size(); i++)
{
if(str[i] == c)
{
count++;
}
}
return count;
}