Thread 106133835 - /g/ [Archived: 216 hours ago]

Anonymous
8/4/2025, 6:03:03 AM No.106133835
20250721_023329
20250721_023329
md5: 57a518f4a3d74750248a554557643665🔍
ChatGPT how do I split a string in slop-lang?
> vibecodes you 50 lines of code of which two lines are actually relevant
Why is it like that?
Replies: >>106133904 >>106133988 >>106134508
Anonymous
8/4/2025, 6:09:11 AM No.106133873
This is what ChatGPT says for C++

std::vector<std::string> split(const std::string& str, char delimiter) {
std::vector<std::string> result;
std::stringstream ss(str);
std::string token;

while (std::getline(ss, token, delimiter)) {
result.push_back(token);
}

return result;
}


Stackexchange answer

std::vector<std::string> split(const std::string& s, const std::string& delimiter) {
std::vector<std::string> tokens;
size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
tokens.push_back(token);
s.erase(0, pos + delimiter.length());
}
tokens.push_back(s);

return tokens;
}


Qt

QStringList list = qstring.split(",");
Anonymous
8/4/2025, 6:16:25 AM No.106133904
>>106133835 (OP)
std::string str = "OP is a faggot";
for (auto word : s | std::views::split(" ")) {
for (char c : part)
std::cout << c;
std::cout << "\n";
}
See? It's not that fucking bad.
Can also be done in Python like so:
for word in "OP is a faggot".split(" "):
print(word)
Anonymous
8/4/2025, 6:31:35 AM No.106133988
>>106133835 (OP)
Because they're optimized for agentic work. When you're asking it how to split a string it understands your prompt as "write me an application that splits a string". Asking it to list all the possible methods to split a string and sum up the pros and cons will be more productive. It's still pretty verbose but paradoxically I find it a boon since reading code is almost always a better way to learn than writing code.
Anonymous
8/4/2025, 6:50:53 AM No.106134071
here's google (gemini)
const sentence = "This is a sample sentence.";
const words = sentence.split(" ");
console.log(words); // Output: ["This", "is", "a", "sample", "sentence."]
Anonymous
8/4/2025, 8:02:35 AM No.106134422
That's hella wasteful.
Use string_view.
Replies: >>106135270
Anonymous
8/4/2025, 8:14:10 AM No.106134508
>>106133835 (OP)
Tell it to be terse and use functional paradigms
Anonymous
8/4/2025, 8:33:56 AM No.106134627
C wins again
#include <stdio.h>
#include <string.h>

int main() {
char str[] = "apple,banana,cherry";
const char *delim = ",";

char *token = strtok(str, delim);
while (token != NULL) {
printf("Token: %s\n", token);
token = strtok(NULL, delim);
}

return 0;
}
Replies: >>106135275
Anonymous
8/4/2025, 8:53:25 AM No.106134723
actually my favorite lang tho
string text = "the quick brown fox jumps";
string[] splitText = text.Split(' ');
Console.WriteLine (string.Join("\nI can put anything here when printing a string array\n", splitText));
Anonymous
8/4/2025, 10:36:02 AM No.106135270
>>106134422
And find and substr, yea
Anonymous
8/4/2025, 10:37:03 AM No.106135275
>>106134627
>strtok
ugh...
Anonymous
8/4/2025, 1:49:24 PM No.106136386
>the guy who makes a daily thread screeching at go needs an AI to tell him how to split a string
you couldn't make it up