Skip to content

Commit fe84792

Browse files
committed
Add TextSplit
1 parent 5a63ca9 commit fe84792

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/Functions.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ RLAPI inline std::string TextInsert(const std::string& text, const std::string&
342342
return "";
343343
}
344344

345+
/**
346+
* Split text into multiple strings
347+
*/
348+
RLAPI inline std::vector<std::string> TextSplit(const std::string& text, char delimiter) {
349+
int count;
350+
const char** split = ::TextSplit(text.c_str(), delimiter, &count);
351+
return std::vector<std::string>(split, split + count);
352+
}
353+
345354
/**
346355
* Find first text occurrence within a string
347356
*/

tests/raylib_cpp_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ int main(int argc, char *argv[]) {
9494
AssertEqual(output, "World");
9595
}
9696

97+
{
98+
std::vector<std::string> output = raylib::TextSplit("Hello|How|Are|You", '|');
99+
AssertEqual(output.size(), 4);
100+
AssertEqual(output[1], "How");
101+
}
102+
97103
// Wave
98104
{
99105
raylib::Wave wave(path + "/resources/weird.wav");

0 commit comments

Comments
 (0)