Strman-java是一个字符串处理工具,可以将开源库引入至项目中,调用方法,方便快捷有效。
通过maven管理工具,引入资源
<dependencies>
<dependency>
<groupId>com.shekhargulati</groupId>
<artifactId>strman</artifactId>
<version>0.2.0</version>
</dependency>
</dependencies>
源代码总共只有3个抽象类,Ascii和HtmlEntities都做的是一些字符初始化工作,Strman.java是核心类,所有字符操作的方法都在Strman中。
使用方法如下:
Strman.isString("s");
方法描述如下:
方法 | 结果 |
append("f", "o", "o", "b", "a", "r") | result => "foobar" |
appendArray("f", new String[]{"o", "o", "b", "a", "r"} | result => "foobar" |
at("foobar", 0) | result => Optional("f") |
between("[abc][def]", "[", "]") | result => ["abc","def"] |
chars("title") | result => "foo bar" |
contains("foo bar","foo") | result => true |
contains("foo bar","FOO", false) | result => true |
containsAll("foo bar", new String[]{"foo", "bar"}) | result => true |
containsAll("foo bar", new String[]{"FOO", "bar"},false) | result => true |
containsAny("bar foo", new String[]{"FOO", "BAR", "Test"}, true) | result => true |
countSubstr("aaaAAAaaa", "aaa") | result => 2 |
countSubstr("aaaAAAaaa", "aaa", false, false) | result => 3 |
endsWith("foo bar", "bar") | result => true |
endsWith("foo Bar", "BAR", false) | result => true |
ensureLeft("foobar", "foo") | result => "foobar" |
ensureLeft("bar", "foo") | result => "foobar" |
ensureLeft("foobar", "FOO", false) | result => "foobar" |
base64Decode("c3RybWFu") | result => "strman" |
base64Encode("strman") | result => "c3RybWFu" |
binDecode("0000000001000001") | result => "A" |
binEncode("A") | result => "0000000001000001" |
decDecode("00065") | result => "A" |
decEncode("A") | result => "00065" |
ensureRight("foo", "bar") | result => "foobar" |
ensureRight("foobar", "bar") | result => "foobar" |
ensureRight("fooBAR", "bar", false) | result => "foobar" |
first("foobar", 3) | result => "foo" |
head("foobar") | result => "f" |
hexDecode("0041") | result => "A" |
hexEncode("A") | result => "0041" |
inequal("a", "b") | result => true |
insert("fbar", "oo", 1) | result => "foobar" |
last("foobarfoo", 3) | result => "foo" |
leftPad("1", "0", 5) | result => "00001" |
lastIndexOf("foobarfoobar", "F", false) | result => 6 |
leftTrim(" strman") | result => "strman" |
prepend("r", "f", "o", "o", "b", "a") | "foobar" |
removeEmptyStrings(new String[]{"aa", "", " ", "bb", "cc", null}) | result => ["aa", "bb", "cc"] |
removeLeft("foofoo", "foo") | result => "foo" |
removeRight("foobar", "bar") | result => "foo" |
removeRight("foobar", "BAR",false) | result => "foo" |
removeSpaces("foo bar") | result => "foobar" |
repeat("1", 3) | result => "111" |
reverse("foo") | result => "oof" |
rightPad("1", "0", 5) | result => "10000" |
rightTrim("strman ") | result => "strman" |
safeTruncate("foo bar", 4, ".") | result => "foo." |
safeTruncate("A Javascript string manipulation library.", 16, "...") | result => "A Javascript..." |
truncate("A Javascript string manipulation library.", 14, "...") | result => "A Javascrip..." |
htmlDecode("Ш") | result => Ш |
htmlEncode("Ш") | result => "Ш" |
slugify("foo bar") | result => "foo-bar" |
transliterate("fóõ bár") | result => "foo bar" |
surround("div", "<", ">") | result => "<div>" |
tail("foobar") | result => "oobar" |
toCamelCase("CamelCase") | result => "camelCase" |
toCamelCase("camel-case") | result => "camelCase" |
toStudlyCase("hello world") | result => "HelloWorld" |
toDecamelize("helloWorld",null) | result => "hello world" |
toKebabCase("hello World") | result => "hello-world" |
toSnakeCase("hello world") | result => "hello_world" |