-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tkns
96 lines (82 loc) · 2.53 KB
/
Tkns
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
#ifndef TKNS_HPP_INCLUDED
#define TKNS_HPP_INCLUDED
#include<string>
#include<vector>
using namespace std;
class Tkns
{
public:
int length;
public:
vector<string> split(string str, string delimiter)
{
vector<string> tokens;
int i=0,j=0;
int strSize;
string temp;
strSize = str.size();
while(i<strSize)
{
if(str[i]!=delimiter[0] && i<strSize)
{
while(str[i]!=delimiter[0] && i<strSize)
{
temp = temp + str[i];
i++;
}
tokens.push_back(temp);
temp="";
}
else
{
i++;
}
}
length = tokens.size();
return tokens;
}
vector<string> split(string str, string startElement, string endElement, string delimiter)
{
string finalString;
int startIndex=str.find(startElement);
int endIndex = str.find(endElement);
finalString.assign(str,startIndex,endIndex);
vector<string> tokens;
string temp;
int i=startIndex;
while(i<=endIndex)
{
if(str[i]!=delimiter[0] && i<=endIndex)
{
while(str[i]!=delimiter[0] && i<=endIndex)
{
//cout<<str[i];
temp = temp + str[i];
i++;
}
tokens.push_back(temp);
temp="";
}
else
{
i++;
}
}
//cout<<"split the string by start and end : "<<finalString<<endl;
//cout<<"str : "<<str<<endl;
//cout<<"startIndex : "<<startIndex<<endl;
//cout<<"endIndex : "<<endIndex<<endl;
return tokens;//this->split(finalString, delimiter);
}
/*void display()
{
int i=0;
while(i < this->length)
{
cout << endl << this->tokens[i] << endl;
i++;
}
cout<<"\n"<<this->length;
}*/
};
#endif // TKNS_H_INCLUDED