Skip to content

jgod/str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Nov 15, 2022
3592444 · Nov 15, 2022

History

22 Commits
Nov 15, 2015
Nov 13, 2015
Nov 15, 2022
Dec 20, 2015
Nov 15, 2022
Dec 20, 2015

Repository files navigation

str

String utility methods (header-only)

requirements

C++11 compiler

usage

Note: all methods for string transformation return new strings.

#include "str.h"
using namespace jgod;

str::indexOf("mystring", "pizza") == -1
str::indexOf("catdog", "dog") == 3
str::lastIndexOf("pizza", "z") == 3
str::includes("code", "cod") == true

str::startsWith("pizza", "pi") == true
str::endsWith("antidisestablishmentarianism", "ism") == true

str::toUpperCase("Joe Shmoe") == "JOE SHMOE"
str::toLowerCase("Joe Shmoe") == "joe shmoe"

str::trim(" x ") == "x"
str::trimLeft(" x ") == "x "
str::trimRight(" x ") == " x"
str::trimRight("Joe Shmoe", ' ') == "Joe"
str::compact("Joe   Shmoe") == "JoeShmoe"

str::split("abcdefghi", 5) == {"abcde", "fghi"}
str::split("/game/items/weapons/ak47", "/") == {"", "game", "items", "weapons", "ak47"}

// replacement functions replace all occurrences
str::replace("aabbccdd", "a", "x") == "xxbbccdd"
str::replace("abcd", "ab", "xy") == "xycd"
str::replace("abcd", {"a", "b", "c"}, "x") == "xxxd"
str::trunc("abcdefghijk", 6) == "abcdef"
str::trunc("abcdefghijk", 6, "...") == "abcdef..."

license

Copyright Justin Godesky. Released under the AGPLv3 License.

About

Simple header-only string utility methods for C++11

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published