Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

codingfarm

StrTok 본문

Algorithm & Data structure/이론

StrTok

scarecrow1992 2021. 4. 22. 10:14

 

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
#include<iostream>
#include<string>
#include<vector>
 
using namespace std;
 
// ex) 2016-09-15 20:59:57.421 0.351s
// 2016-09-15 20:59:58.299 8
void StrTok(string& org, vector<string>& ret, const string& delims) {
    ret.clear();
    string new_str;
    for (int index = 0; index < org.size(); index++) {
        for (int i = 0; i < delims.size(); i++) {
            if (org[index] == delims[i]) {
                ret.push_back(new_str);
                new_str.clear();
                index++;
                break;
            }
        }
        new_str.push_back(org[index]);
    }
 
    if (new_str[0!= '\0')
        ret.push_back(new_str);
}
 
 
int main(void) {
    string delims = ":. s";
    string str = "2016-09-15 20:59:57.421 0.351s";
    vector<string> ret;
 
    StrTok(str, ret, delims);
 
    str = "2016-09-15 20:59:58.299 8";
    StrTok(str, ret, delims);
 
    return 0;
}
cs

 

 

Comments