-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstringStudy.h
More file actions
107 lines (92 loc) · 2.29 KB
/
stringStudy.h
File metadata and controls
107 lines (92 loc) · 2.29 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include <string>
#include <sstream>
using namespace std;
namespace gugw {
//耗时相对itoa和sprintf延长了八倍,在无法通过其他环节提升速度时候,考虑这个替换为sprintf。
template <typename T>
string to_string(T value)
{
ostringstream oss;
oss << value;
return oss.str();
}
template <typename T>
T string_to(string value, T)
{
T result;
istringstream iss(value);
iss >> result;
return result;
}
vector<string> split(string str, char delimiter) {
vector<string> arrays;
string tmpstr;
while (!str.empty()) {
int ind = str.find_first_of(delimiter);
if (ind == -1) {
arrays.push_back(str);
str.clear();
}
else {
arrays.push_back(str.substr(0, ind));
str = str.substr(ind + 1, str.size() - ind - 1);
}
}
return arrays;
}
class StringStudy
{
string str;
public:
void testSwap()
{
str = "bbbbbbb";
string str2 = "aaaaa";
std::cout << "now str=" << str << " str2=" << str2 << std::endl;
str.swap(str2);
std::cout << "now str=" << str << " str2=" << str2 << std::endl;
}
void testSubAndFindStr()
{
int i = 0;
int testCount = 100;
string result;
string sessionId;
string frontId;
string orderref;
//mts1 = tt1.getNowForMicro();
while (i < testCount) {
sessionId = to_string(223322233);
frontId = to_string(111);
orderref = " 3333333";
result = sessionId.append(frontId).append(orderref);
i++;
}
//mts2 = tt1.getNowForMicro();
//cout << (double)(mts2 - mts1).count() / testCount << endl;
i = 0;
//mts1 = tt1.getNowForMicro();
while (i < testCount) {
char OrderRef[11 + 11 + 13];
sprintf(OrderRef, "%10d@", 223322233);
sprintf(&OrderRef[11], "%10d@", 111);
strcpy_s(&OrderRef[22], 13, " 333333311");
i++;
}
//mts2 = tt1.getNowForMicro();
//cout << (double)(mts2 - mts1).count() / testCount << endl;
string ss = "123123@111@ 3333";
int index = ss.find('@');
string s1 = ss.substr(0, index);
int index2 = ss.find('@', index + 1);
string s2 = ss.substr(index + 1, index2 - index - 1);
int index3 = ss.find('@', index2 + 1);
string s3 = ss.substr(index2 + 1);
index = ss.find_last_of('@');
string s4 = ss.substr(index + 1);
cout << s1 << " " << s2 << " " << s3 << " " << s4 << endl;
system("pause");
}
};
}