当前位置: 首页 > 工具软件 > Strman-Java > 使用案例 >

用于字符串处理的 Java 8 库

鱼安然
2023-12-01

文档地址:https://github.com/shekhargulati/strman-java/wiki

一、Maven 项目需要在 pom.xml 文件中添加以下依赖

<dependency>
    <groupId>com.shekhargulati</groupId>
    <artifactId>strman</artifactId>
    <version>0.4.0</version>
</dependency>

二、介绍

1、append

import static strman.Strman.append
append("f", "o", "o", "b", "a", "r")
// result => "foobar

2、appendArray

import static strman.Strman.appendArray
appendArray("f", new String[]{"o", "o", "b", "a", "r"}
// result => "foobar"

3、at

import static strman.Strman.at
at("foobar", 0)
// result => Optional("f")

4、between

import static strman.Strman.between
between("[abc][def]", "[", "]")
// result => ["abc","def"]

5、chars

import static strman.Strman.chars
chars("title")
// result => ["t", "i", "t", "l", "e"]

6、charsCount

import static strman.Strman.charsCount
charsCount("abca")
// result => Map(("a",2),("b",1),("c",1))

7、collapseWhitespace

import static strman.Strman.collapseWhitespace
collapseWhitespace("foo    bar")
// result => "foo bar"

8、contains

import static strman.Strman.contains
contains("foo bar","foo")
// result => true

contains("foo bar","FOO", false) // turning off case sensitivity
// result => true

9、containsAll

import static strman.Strman.containsAll
containsAll("foo bar", new String[]{"foo", "bar"})
// result => true

containsAll("foo bar", new String[]{"FOO", "bar"},false)
// result => true

10、containsAny

import static strman.Strman.containsAny
containsAny("bar foo", new String[]{"FOO", "BAR", "Test"}, true)
// result => true

11、countSubstr

import static strman.Strman.countSubstr
countSubstr("aaaAAAaaa", "aaa")
// result => 2
countSubstr("aaaAAAaaa", "aaa", false, false)
// result => 3

12、endsWith

import static strman.Strman.endsWith
endsWith("foo bar", "bar")
// result => true
endsWith("foo Bar", "BAR", false)
// result => true

13、ensureLeft

import static strman.Strman.ensureLeft
ensureLeft("foobar", "foo")
// result => "foobar"
ensureLeft("bar", "foo")
// result => "foobar"
ensureLeft("foobar", "FOO", false)
// result => "foobar"

14、base64Decode

import static strman.Strman.base64Decode
base64Decode("c3RybWFu")
// result => "strman"

15、base64Encode

import static strman.Strman.base64Encode
base64Encode("strman")
// result => "c3RybWFu"

16、binDecode

import static strman.Strman.binDecode
binDecode("0000000001000001")
// result => "A"

17、binEncode

import static strman.Strman.binEncode
binEncode("A")
// result => "0000000001000001"

18、decDecode

import static strman.Strman.decDecode
decDecode("00065")
// result => "A"

19、decEncode

import static strman.Strman.decEncode
decEncode("A")
// result => "00065"

20、ensureRight

import static strman.Strman.ensureRight
ensureRight("foo", "bar")
// result => "foobar"

ensureRight("foobar", "bar")
// result => "foobar"

ensureRight("fooBAR", "bar", false)
// result => "foobar"

21、first

import static strman.Strman.first
first("foobar", 3)
// result => "foo"

22、head

import static strman.Strman.head
head("foobar")
// result => "f"

23、hexDecode

import static strman.Strman.hexDecode
hexDecode("0041")
// result => "A"

24、hexEncode

import static strman.Strman.hexEncode
hexEncode("A")
// result => "0041"

25、inequal

import static strman.Strman.inequal
inequal("a", "b")
// result => true

26、insert

import static strman.Strman.insert
insert("fbar", "oo", 1)
// result => "foobar"

27、last

import static strman.Strman.last
last("foobarfoo", 3)
// result => "foo

28、leftPad

import static strman.Strman.leftPad
leftPad("1", "0", 5)
// result => "00001"

29、lastIndexOf

import static strman.Strman.lastIndexOf
lastIndexOf("foobarfoobar", "F", false)
// result => 6

30、leftTrim

import static strman.Strman.leftTrim
leftTrim("     strman")
// result => "strman"

31、prepend

prepend("r", "f", "o", "o", "b", "a")
// "foobar"

32、removeEmptyStrings

removeEmptyStrings(new String[]{"aa", "", "   ", "bb", "cc", null})
// result => ["aa", "bb", "cc"]

33、removeLeft

removeLeft("foofoo", "foo")
// "foo"

34、removeNonWords

removeNonWords("foo&bar-")
// result => "foobar"

35、removeRight

removeRight("foobar", "bar")
// result => "foo"
removeRight("foobar", "BAR",false)
// result => "foo

36、removeSpaces

removeSpaces("foo bar")
// result => "foobar"

37、repeat

repeat("1", 3)
// result  => "111"

38、reverse

reverse("foo")
// result => "oof"

39、rightPad

rightPad("1", "0", 5)
// result => "10000"

40、rightTrim

rightTrim("strman   ")
// result => "strman"

41、safeTruncate

safeTruncate("foo bar", 4, ".")
// result => "foo."
safeTruncate("A Javascript string manipulation library.", 16, "...")
// result => "A Javascript..."

42、truncate

truncate("A Javascript string manipulation library.", 14, "...")
// result => "A Javascrip..."

43、htmlDecode

htmlDecode("&SHcy;")
// result => Ш

44、htmlEncode

htmlEncode("Ш")
// result => "&SHcy;"

45、shuffle

shuffle("shekhar")

46、slugify

slugify("foo bar")
// result => "foo-bar"

47、transliterate

transliterate("fóõ bár")
// result => "foo bar"

48、trimEnd

trimEnd("   abc   ")
// result => Optional("   abc")
trimEnd("")
// result Optional.empty()

49、surround

surround("div", "<", ">"
// result => "<div>s"

50、tail

tail("foobar")
// result => "oobar"

51、toCamelCase

toCamelCase("CamelCase")
// result => "camelCase"
toCamelCase("camel-case")
// result => "camelCase"

52、toStudlyCase

toStudlyCase("hello world")
// result => "HelloWorld"

53、toDecamelize

toDecamelize("helloWorld",null)
// result => "hello world"

54、toKebabCase

toKebabCase("hello World")
// result => "hello-world"

55、toSnakeCase

toSnakeCase("hello world")
// result => "hello_world"

56、upperFirst

upperFirst("fred")
// result => "Fred"

57、words

words("This is a string, with words!")
// result => ["This", "is", "a", "string", "with", "words"]

58、isEnclosedBetween

isEnclosedBetween("{{shekhar}}", "{{", "}}")
// result => true

59、join

join(new String[]{"hello","world","123"}, ";")
// result => "hello;world;123")

60、isBlank

isBlank("")
// result => true)
isBlank(null)
// result => true)
isBlank("test")
// result => false)

61、underscored

underscored("MozTransform")
// result => "moz_transform")

62、zip

zip("abc", "def")
// result => ["ad", "be", "cf"]

zip("abc", "d")
// result => ["ad"]

63、lines

lines("Hello\r\nWorld")
// result => ["Hello", "World"]

64、dasherize

dasherize("the_dasherize_string_method")
// result => "the-dasherize-string-method"

65、humanize

humanize("the_humanize_method")
// result => "The humanize method"

66、swapCase

swapCase("AaBbCcDdEe")
// result => "aAbBcCdDeE"

67、chop

chop("whitespace", 3);
// result => ["whi", "tes", "pac", "e"]

 

 

 

 

 

 类似资料: