Skip to content

Commit 334d586

Browse files
committed
Update consolidated snippets
1 parent 0a0435e commit 334d586

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

public/consolidated/all_snippets.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
"title": "Reverse String",
88
"description": "Reverses the characters in a string.",
99
"code": [
10-
"string reverseString(const string& input) {",
11-
" string reversed = input;",
12-
" reverse(reversed.begin(), reversed.end()); // Using STL's reverse function",
10+
"#include <string>",
11+
"#include <algorithm>",
12+
"",
13+
"std::string reverseString(const std::string& input) {",
14+
" std::string reversed = input;",
15+
" std::reverse(reversed.begin(), reversed.end());",
1316
" return reversed;",
1417
"}"
1518
],
@@ -20,6 +23,33 @@
2023
"utility"
2124
],
2225
"author": "Vaibhav-kesarwani"
26+
},
27+
{
28+
"title": "Split String",
29+
"description": "Splits a string by a delimiter",
30+
"code": [
31+
"#include <string>",
32+
"#include <vector>",
33+
"",
34+
"std::vector<std::string> split_string(std::string str, std::string delim) {",
35+
" std::vector<std::string> splits;",
36+
" int i = 0, j;",
37+
" int inc = delim.length();",
38+
" while (j != std::string::npos) {",
39+
" j = str.find(delim, i);",
40+
" splits.push_back(str.substr(i, j - i));",
41+
" i = j + inc;",
42+
" }",
43+
" return splits;",
44+
"}"
45+
],
46+
"tags": [
47+
"cpp",
48+
"string",
49+
"split",
50+
"utility"
51+
],
52+
"author": "saminjay"
2353
}
2454
]
2555
},

0 commit comments

Comments
 (0)