casa
5.7.0-16
|
Split a String into its elements. More...
#include <ArrayUtil.h>
Public Member Functions | |
Vector< String > | stringToVector (const String &string, char delim= ',') |
Vector< String > | stringToVector (const String &string, const Regex &delim) |
Split a String into its elements.
stringToVector converts a 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<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 101 of file ArrayUtil.h.
Vector<String> casacore::ArrayUtil_global_functions_stringToVector::stringToVector | ( | const String & | string, |
char | delim = ',' |
||
) |
Vector<String> casacore::ArrayUtil_global_functions_stringToVector::stringToVector | ( | const String & | string, |
const Regex & | delim | ||
) |