This library implements many commonly used but not natively supported function in std::string, like Split, Join, Trim, Compact, ReplaceAll, ToLower, ToUpper, Repeat, ReadFile, WriteFile, etc.
make test
Passing: Split(s, delim, false)
Passing: Split(s, delim, true)
Passing: Join(res, delim, false)
Passing: Join(res, delim, true)
Passing: Compact(res)
Passing: Trim(" hi ")
Passing: Repeat("-", 5)
Passing: ReplaceAll("monday morning", "mo", "kk")
Passing: ToUpper("abcd")
Passing: ToLower("ABCD")
Passing: ReadFile("test_readfile.txt")
Passing: WriteFile("test_writefile.txt", "abcde")
Result: 12/12 Completed.
see example: test.cpp
see source code: string-utils.h
see demo: demo
vector<string> v = Split("one,two,three", ","); // v: ["one", "two", "three"]vector<string> v;
v.push_back("1");
v.push_back("2");
v.push_back("3");
string s = Join(v, ":"); // s: "1:2:3"string s = Trim(" hi "); // v: "hi"string s = Repeat("#", 5); // v: "#####"vector<string> v = ReplaceAll("1-2-3-4", "-", "#"); // v: "1#2#3#4"remove empty string
vector<string> v;
v.push_back("1");
v.push_back("");
v.push_back("2");
v.push_back("3");
v.push_back("");
// v: ["1", "", "2", "3", ""]
v = Compact(v);
// v: ["1", "2", "3"]string s = ToLower("ABCD"); // v: "abcd"string s = ToUpper("abcd"); // v: "ABCD"read file to string
string content = ReadFile(...file path...);write string to file
string content = "...";
WriteFile(...file path..., content);build and run: make demo
see demo: demo
We love contributions! If you'd like to contribute please submit a pull request.