Evo C++ Library v0.5.1
String Conversion

This goes over converting strings to simpler types like numbers.

The reverse is covered by String Formatting.

This also goes over more advanced conversion using Generic Conversion and split/join features.

Bool Conversion

Convert strings to bool:

#include <evo/string.h>
using namespace evo;
int main() {
Bool val1 = String("true").boolval();
bool val2 = String("true").getbool<bool>();
return 0;
}
Number Conversion

Convert strings to numbers:

#include <evo/string.h>
using namespace evo;
int main() {
Int val1 = String("123").num();
FloatD val2 = String("1.2").numfd();
int val3 = String("123").getnum<int>();
double val4 = String("1.2").getnumf<double>();
return 0;
}
Generic Conversion

Generic conversion is supported via templates:

#include <evo/string.h>
using namespace evo;
int main() {
Bool val1 = String("1").convert<Bool>();
Int val2 = String("123").convert<Int>();
FloatD val3 = String("1.2").convert<FloatD>();
int val4 = String("123").convert<int>();
double val5 = String("1.2").convert<double>();
SubString val6 = String("1.2").convert<SubString>();
return 0;
}

Reverse generic conversion is also supported. See String Formatting.

Note: Generic conversion to an incompatible type will result in a compiler error.

Join Conversion

List, Set, and Map collections can be joined into a delimited string using generic conversion.

See:

Split Conversion

A delimited string can be split into List, Set, and Map collections using generic conversion.

See: