C++ Single-header library containing simple string utilities. Useful when you don't feel like using a massive library such as boost to split some text in a small command line utility.
All you gotta do is include the header file in your code. No compilation needed.
You can place the file directly next to your source, or configure some sort of include path for your project, it's up to you.
For ease of use, I'd use the following line:
namespace es = easystring;
This lets you shorten your lines a lot, for example es::split
vs easystring::split
makes a difference.
Makes the string uppercase.
Makes the string lowercase.
Adds amount
of character
to the left of the string.
Adds amount
of character
to the right of the string.
Turns the string into title case, ex. "hello wORLD!" -> "Hello World"
Splits the string into a vector of strings, using the delimiter.
For example:
es::split("Hello::world()", "::") -> ["Hello", "world()"]
Left-pads the string with character
until the whole string reaches the specified length
.
This is useful when you want to align things in the console.
Same thing as left_justify
, but adds the characters on the right instead.
Removes all whitespace from the left of the string.
Removes all whitespace from the right of the string.
Removes all leading and trailing whitespace from the string.
Reverses a string (duh).
Returns true
if the string starts with the specified prefix.
Returns false
if the string ends with the specified suffix.
Returns true
if the string contains the other one.
Returns true
if all characters in the string are uppercase.
Returns true
if all characters in the string are lowercase.
Replaces all occurences of from
with to
in the string.
The map is supposed to be a unordered_map
of strings to strings.
It will perform a replace on the string
according to the map.
Join all the strings together, optionally with a separator. By default there's no space between the joined strings.
Capitalize the first letter of the string.
Splits the string into two at the specified index, and returns an std::pair containing both of them.
For example, es::partition("Hello", 2) => ("He", "llo")
.
Converts a string into a vector of char
s.
Repeats the string amount
of times.