casacore
|
Split a std::string into its elements. More...
#include <ArrayUtil.h>
Public Member Functions | |
Vector< std::string > | strToVector (const std::string &string, char delim= ',') |
Vector< std::string > | strToVector (const std::string &string, const std::regex &delim) |
Split a std::string into its elements.
stringToVector converts a std::string to a Vector of Strings.
The function stringToVector splits a string into its elements using the given delimiter and returns them in a Vector<std::string>
. The default delimiter is a comma (,). It is very useful when using a function taking a vector of strings as shown in the example.
A more advanced way of splitting a string is by using a regular expression as delimiter. It makes it, for example, possible to treat whitespace around a comma as part of the delimiter (as shown in an example below).
A string with length 0 results in a zero-length vector.
As shown in the example, the function stringToVector makes passing a Vector of Strings far easier.
This results in a vector with 4 elements containing the values "abc", "def ", "", and "gh". The vector is passed to someFunction. This is far easier than having to do it as:
The following example shows how to use a delimiter consisting of a comma surrounded by possible whitespace.
Definition at line 99 of file ArrayUtil.h.
Vector<std::string> casacore::ArrayUtil_global_functions_stringToVector::strToVector | ( | const std::string & | string, |
char | delim = ',' |
||
) |
Vector<std::string> casacore::ArrayUtil_global_functions_stringToVector::strToVector | ( | const std::string & | string, |
const std::regex & | delim | ||
) |