Bash++
Bash++ compiler internal documentation
|
#include <string>
#include <vector>
Go to the source code of this file.
Functions | |
std::vector< std::string > | explode (const std::string &input, char delimiter, bool can_escape=false, int maximum_number_of_elements=0, bool preserve_empty=false) |
Splits a string into a vector of strings based on a delimiter. | |
std::vector< std::string > explode | ( | const std::string & | input, |
char | delimiter, | ||
bool | can_escape, | ||
int | maximum_number_of_elements, | ||
bool | preserve_empty | ||
) |
Splits a string into a vector of strings based on a delimiter.
Copyright (C) 2023-2025 rail5
This function mimics the behavior of PHP's explode
function. It splits the input string into separate strings using the provided delimiter. If can_escape
is true, it does not split where the delimiter is backslash-escaped and removes said backslash from the string If maximum_number_of_elements
is set to a value greater than zero, it limits how many elements can be split apart. If the limit is reached, the rest of the string is appended to the last element. If maximum_number_of_elements
is zero, it splits the string into as many elements as it needs to. If preserve_empty
is true, it preserves empty strings in the output vector. E.g, if the input string is "Test,,one,,two,,three" and the delimiter is ",", it will return {"Test", "", "one", "", "two", "", "three"}. If preserve_empty
is false, it will return {"Test", "one", "two", "three"}.