-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathSolution.cpp
39 lines (32 loc) · 897 Bytes
/
Solution.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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/** Gets a string and separe through a separator _sep and returns into a
* std::vector<std::string> */
std::vector<std::string> split(std::string _str, char _sep) {
std::vector<std::string> v;
int begin = 0;
for (int i=0 ; i < _str.size() ; i++){
if (_str[i] == _sep) {
v.push_back( _str.substr(begin, i-begin) );
begin = i+1;
}
}
v.push_back(_str.substr(begin, _str.size()));
return v;
};
int main() {
string str1 = "name.midname.lastname";
vector<string> vecStr1 = split(str1, '.');
for (string& s : vecStr1) {
cout << s << endl;
}
cout << endl;
string str2 = "myname@emailservice.com";
vector<string> vecStr2 = split(str2, '@');
for (string& s : vecStr2) {
cout << s << endl;
}
return 0;
}