|
14 | 14 | ],
|
15 | 15 | "tags": ["cpp", "array", "reverse", "utility"],
|
16 | 16 | "author": "Vaibhav-kesarwani"
|
| 17 | + }, |
| 18 | + { |
| 19 | + "title": "Split String", |
| 20 | + "description": "Splits a string by a delimiter", |
| 21 | + "code": [ |
| 22 | + "std::vector<std::string> split_string(std::string str, std::string delim) {", |
| 23 | + " std::vector<std::string> splits;", |
| 24 | + " int i = 0;", |
| 25 | + " int j = str.find(delim);", |
| 26 | + " int inc = delim.length();", |
| 27 | + " while (j != std::string::npos) {", |
| 28 | + " splits.push_back(str.substr(i, j - i));", |
| 29 | + " i = j + inc;", |
| 30 | + " j = str.find(delim, i);", |
| 31 | + " }", |
| 32 | + " splits.push_back(str.substr(i));", |
| 33 | + " return splits;", |
| 34 | + "}" |
| 35 | + ], |
| 36 | + "tags": ["cpp", "string", "split", "utility"], |
| 37 | + "author": "saminjay" |
17 | 38 | }
|
18 | 39 | ]
|
19 | 40 | }
|
|
0 commit comments