String Manipulation¶
There are a couple classes and functions to help manipulate
strings of text. Conversion routines for c std::string
objects are given in src/base/string_conv.h
and include
o2scl::btos()
- boolean value to stringo2scl::dtos()
- double to stringo2scl::itos()
- integer to stringo2scl::ptos()
- pointer to stringo2scl::stob()
- string to boolean valueo2scl::stod()
- string to double (uses C++11std::stod()
)o2scl::stoi()
- string to integer (uses C++11std::stoi()
)o2scl::stoszt()
- string tosize_t
o2scl::szttos()
-size_t
to string
(While o2scl::dtos()
and similar functions have been
implemented in std::to_string
, the O2scl versions have
been written to allow a bit more flexibility.)
There are also a set of conversion functions which return and integer error code instead of throwing an exception
o2scl::stoi_nothrow()
- string to integero2scl::stoszt_nothrow()
-size_t
to string
The columnify class converts a set of
strings into nicely formatted columns by padding with the
necessary amount of spaces. This class operates on string objects
of type std::string
, and also works will for formatting columns
of floating-point numbers. This class is used to provide output
for matrices in the functions o2scl::matrix_out()
.
The format_float class will reformat double precision numbers into a form appropriate for HTML or LaTeX documents.
A related function, o2scl::screenify()
, reformats a column
of strings into many columns stored row-by-row in a new string array.
It operates very similar to the way the classic Unix command ls
organizes files and directories in multiple columns in order to save
screen space.
The function o2scl::function_to_double()
converts strings
like "1.0/3.0"
and "exp(cos(-1.0e-2))"
to double-precision
floating point numbers using calculator.
The function o2scl::size_of_exponent()
returns 2 or 3,
depending on the number of characters in the exponent when a floating
point number is output to the screen.
Finally, the function o2scl::count_words()
counts the
number of “words” in a string, which are delimited by whitespace.