-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathstring_helper.h
More file actions
52 lines (37 loc) · 863 Bytes
/
string_helper.h
File metadata and controls
52 lines (37 loc) · 863 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
47
48
49
50
51
52
#ifndef ICE_STR
#define ICE_STR
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
const string trim(const string &pString,
const string &pWhitespace = " \n\t");
string replaceStrChar(string str, const string &replace, char ch);
void replaceAll(string &str, char &x, char &y);
/**
* @fn template <typename T> T str_to(string s)
* @param s String to convert
*
* Converts a string to some other type T
*/
template<typename T>
T str_to(string s) {
stringstream ss(s);
T res = T();
ss >> res;
return res;
}
template<typename T>
pair<T, bool> check_str_to(string s) {
stringstream ss(s);
T res = T();
ss >> res;
return pair<T, bool>(res, !ss.fail());
}
template<typename T>
string to_str(T element) {
stringstream ss;
ss << element;
return ss.str();
}
#endif