StrSplit
- Function
- August 22, 2025
Table of Contents
StrSplit
StrSplit
Description
Split the given Str object into multiple Str objects stored in a vector of Str objects. Each Str object in returned vector is a new Str object and hence must be deinited after use. Calling VecDeinit()
on the returned vector will do that for you automatically for all the objects. This is best used when iterating over a delimited data is not the only goal, but also other modifications like stripping over whitespaces from returned Str objects.
Parameters
Name | Direction | Description |
---|---|---|
str | in | Str object to split |
key | in | Zero-terminated char pointer value to split based on |
Success
Strs vector of non-zero length
Failure
Strs vector of zero-length
Usage example (Cross-references)
- In
Str.c:117
:
}
Strs StrSplit(Str* s, const char* key) {
ValidateStr(s);
- In
Main.c:6
:
Str file = StrInit();
if (ReadCompleteFile("Bin/Demangler/CppNameManglingGrammar", &file.data, &file.length, &file.capacity)) {
Strs lines = StrSplit(&file, "\n");
// Use the fixed VecForeachPtr macro
- In
Str.Ops.c:163
:
// Test string split functions
bool test_str_split(void) {
printf("Testing StrSplit and StrSplitToIters\n");
// Test StrSplit
- In
Str.Ops.c:167
:
// Test StrSplit
Str s = StrInitFromZstr("Hello,World,Test");
Strs split = StrSplit(&s, ",");
bool result = (split.length == 3);