forked from chandrasekharanil/Assignment-2-Group-4-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringhelper.h
47 lines (41 loc) · 1.15 KB
/
stringhelper.h
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
#pragma once
//----------------------------------------------------------------------------------------
// Copyright © 2007 - 2017 Tangible Software Solutions Inc.
// This class can be used by anyone provided that the copyright notice remains intact.
//
// This class is used to replace some string methods, including
// conversions to or from strings.
//----------------------------------------------------------------------------------------
#include <string>
#include <sstream>
#include <vector>
class StringHelper
{
public:
static std::vector<std::wstring> split(const std::wstring &source, wchar_t delimiter)
{
std::vector<std::wstring> output;
std::wistringstream ss(source);
std::wstring nextItem;
while (std::getline(ss, nextItem, delimiter))
{
output.push_back(nextItem);
}
return output;
}
template<typename T>
static std::wstring toString(const T &subject)
{
std::wostringstream ss;
ss << subject;
return ss.str();
}
template<typename T>
static T fromString(const std::wstring &subject)
{
std::wistringstream ss(subject);
T target;
ss >> target;
return target;
}
};