Giter VIP home page Giter VIP logo

stringutils's Introduction

StringUtils

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.

Test

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.

Usage

see example: test.cpp

see source code: string-utils.h

see demo: demo

Split

vector<string> v = Split("one,two,three", ","); // v: ["one", "two", "three"]

Join

vector<string> v;
v.push_back("1");
v.push_back("2");
v.push_back("3");
string s = Join(v, ":"); // s: "1:2:3"

Trim

string s = Trim(" hi "); // v: "hi"

Repeat

string s = Repeat("#", 5); // v: "#####"

ReplaceAll

vector<string> v = ReplaceAll("1-2-3-4", "-", "#"); // v: "1#2#3#4"

Compact

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"]

ToLower

string s = ToLower("ABCD"); // v: "abcd"

ToUpper

string s = ToUpper("abcd"); // v: "ABCD"

ReadFile

read file to string

string content = ReadFile(...file path...);

WriteFile

write string to file

string content = "...";
WriteFile(...file path..., content);

Demo

build and run: make demo

see demo: demo

Contributing

We love contributions! If you'd like to contribute please submit a pull request.

License

License.md

stringutils's People

Contributors

hungtatai avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.