-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathstring_helper.h
More file actions
executable file
·31 lines (26 loc) · 870 Bytes
/
string_helper.h
File metadata and controls
executable file
·31 lines (26 loc) · 870 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
#pragma once
#include "utils.h"
class StringHelper{
public:
static std::vector<std::string> Split(const std::string& str, char splitChar){
std::vector<std::string> ret;
int start = 0;
for (int i = 0, len = str.length(); i < len; i++){
if (str[i] == splitChar){
ret.push_back(str.substr(start, i - start));
start = i + 1;
}
}
ret.push_back(str.substr(start));
return ret;
}
static std::string RemoveSpaces(const std::string& str){
std::vector<char> ret;
for (int i = 0, len = str.length(); i < len; i++){
char c = str[i];
if (c != ' ' && c != '\t' && c != '\n'&& c != '\r')
ret.push_back(c);
}
return std::string(ret.begin(), ret.end());
}
};