-
Notifications
You must be signed in to change notification settings - Fork 41
/
CStringUtil.cpp
67 lines (60 loc) · 1.33 KB
/
CStringUtil.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stdafx.h"
#include "CStringUtil.h"
CStringUtil::CStringUtil()
{
}
CStringUtil::~CStringUtil()
{
}
void CStringUtil::Spil(const CString & text, const TCHAR * separater, std::vector<CString>& result)
{
int pre = 0, cur = 0;
CString strcopytext = text;
strcopytext.Trim(_T(" "));
if (strcopytext.Find(separater,0)<0)
{
if (strcopytext.GetLength() > 0)
{
result.push_back(strcopytext);
}
}
else
{
int textLemgth = strcopytext.GetLength();
while (true)
{
CString strspil("");
cur = strcopytext.Find(separater, pre);
if (cur>0)
{
strspil=strcopytext.Mid(pre, cur-pre);
if (strspil.GetLength()>0)
{
result.push_back(strspil);
}
pre =static_cast<int>(cur+_tcslen(separater));
}
else
{
strspil = strcopytext.Mid(pre,textLemgth);
if (strspil.GetLength()>0)
{
result.push_back(strspil);
}
break;
}
}
}
}
void CStringUtil::join(std::vector<CString>& result, const TCHAR * separater, CString & text)
{
text = _T("");
if (result.size()>0)
{
for (size_t i = 0; i < result.size(); i++)
{
text += result[i] + separater;
}
text = text.TrimRight(separater);
}
}