strman-java (java string tool library)

1. Introduction

strman-java is a string processing library for Java8, which is inspired by dleitee/strman.
Strmen-java is a string processing tool that you can import into your project through maven. In addition to Java's own string handling, we can also use StringUtils in Apache Common Langs to simplify String operations. But the above two methods are still somewhat insufficient for the string processing that is most likely to be encountered in our daily programming. Strmen-java provides us with a very complete and powerful solution that can be used to solve almost all string processing scenarios.

Second, get started

In order to use strman-java in your Java application, you can download this package and add it to the lib directory of your project. If you use Maven for project management, you only need to add it in your pom. Add the following dependencies to xml:
<dependency>

    <groupId>com.shekhargulati</groupId>

    <artifactId>strman</artifactId>

     <version>0.2.0</version>

      <type>jar</type>

</dependency>
If you are a Gradle user, add the following code to the build.gradle file:
compile(group: 'com.shekhargalati', name: 'strman', version: '0.2.0', ext: 'jar'){ 
    transitive=true
}

 


  String s1 = Strman.append("f", "o", "o", "b", "a", "r");
   System.out.println("append:" + s1); // result = > "foobar"// prepend appends any number of strings to a string
       

        String s1pre = Strman.prepend("r", "f", "o", "o", "b", "a");
        System.out.println("prepend:" + s1pre); // result = > "foobar"// appendArray appends the elements of a string array after a string
       

String s2 = Strman.appendArray("f", new String[]{"o", "o", "b", "a", "r"});
        System.out.println("append:" + s2 ); // result => "foobar"// at Get the corresponding character according to the index of the string. If the index is negative, it will be fetched in reverse, and if it exceeds, an exception will be thrown
       

Optional<String> s3 = Strman.at("foobar", 3);
        System.out.println("at:" + s3.get()); // result => "b"// between gets a string , an array of strings between the start string and the end string
       

String[] s4 = Strman.between("[abc], [def]", "[", "]");
        System.out.println("between:" + Arrays.toString(s4)); // result => "[abc, def]"// chars Get a string array of all characters in a string
       

String[] s5 = Strman.chars("title");
        System.out.println("chars:" + Arrays.toString(s5)); // result => "[t, i, t, l, e] "// collapseWhitespace replaces consecutive multiple spaces with one space
       

String s6 = Strman.collapseWhitespace("foo bar");
        System.out.println("chars:" + s6); // result => "foo bar"// contains determines whether a string contains another string, The third parameter, indicating whether the string is case sensitive
       

boolean s7 = Strman.contains("foo bar", "foo");
        boolean s8 = Strman.contains("foo bar", "FOO", false);
        System.out.println("contains:" + s7 + " , " + s8); // result => "true, true"// containsAll determines whether a string contains all elements in a string array
       

boolean s9 = Strman.containsAll("foo bar", new String[]{"foo", "bar"});
        boolean s10 = Strman.containsAll("foo bar", new String[]{"FOO", "bar "}, false);
        System.out.println("containsAll:" + s9 + ", " + s10); // result => "true, true"// containsAny determines whether a string is contained in a string array any element of
       

boolean s11 = Strman.containsAny("foo bar", new String[]{"FOO", "BAR", "Test"}, false);
        System.out.println("containsAny:" + s11); // result => "true"// countSubstr determines the number of strings that contain a string long s12 = Strman.countSubstr("aaaAAAaaa", "aaa");
       

long s13 = Strman.countSubstr("aaaAAAaaa", "aaa", false, false);
        System.out.println("countSubstr:" + s12 + ", " + s13); // result => "2, 3" // endsWith determines whether a string ends with a string
       

boolean s14 = Strman.endsWith("foo bar", "bar");
        boolean s15 = Strman.endsWith("foo bar", "BAR", false);
        System.out.println("endsWith:" + s14 + " , " + s15); // result => "true, true" // ensureLeft ensures a string starts with a string, if not, appends the string and returns the string result
       

String s16 = Strman.ensureLeft("foobar", "foo");
        String s17 = Strman.ensureLeft("bar", "foo");
        String s18 = Strman.ensureLeft("foobar", "FOO", false);
        System.out.println("ensureLeft:" + s16 + ", " + s17 + ", " + s18);
        // result => "foobar, foobar, foobar"// ensureRight ensures that a string ends with a certain string at the beginning, if not, append the string in front and return the string result
       

String s16r = Strman.ensureRight("foobar", "bar");
        String s17r = Strman.ensureRight("foo", "bar");
        String s18r = Strman.ensureRight("fooBAR", "bar", false);
        System.out.println("ensureRight:" + s16r + ", " + s17r + ", " + s18r);
        // result => "foobar, foobar, fooBAR"// base64Encode 将字符串转成Base64编码的字符串
       

String s19 = Strman.base64Encode("strman");
        System.out.println("base64Encode:" + s19); // result => "c3RybWFu"// binDecode converts binary code (16 bits) into string characters
        String s20 = Strman.binDecode("0000000001000001");
        System.out.println("binDecode:" + s20); // result => "A"// binEncode converts string characters to binary code (16 bits)
       

String s21 = Strman.binEncode("A");
        System.out.println("binEncode:" + s21); // result => "0000000001000001"// decDecode converts decimal encoding (5 digits) into string characters
       

String s22 = Strman.decDecode("00065");
        System.out.println("decDecode:" + s22); // result => "A"// decEncode converts the string to decimal encoding (5 digits)
       

String s23 = Strman.decEncode("A");
        System.out.println("decEncode:" + s23); // result => "00065"// first get the string from the beginning of the string to index n
       

String s24 = Strman.first("foobar", 3);
        System.out.println("first:" + s24); // result => "foo"// last gets the string with index n from the end of the string
       

String s24l = Strman.last("foobar", 3);
        System.out.println("last:" + s24l); // result => "bar"// head gets the first character of the string
       

String s25 = Strman.head("foobar");
        System.out.println("head:" + s25); // result => "f"// hexDecode converts string characters to hex code (4 bits)
       

String s26 = Strman.hexDecode("0041");
        System.out.println("hexDecode:" + s26); // result => "A"// hexEncode converts hexadecimal encoding (4 bits) into characters string character
       

String s27 = Strman.hexEncode("A");
        System.out.println("hexEncode:" + s27); // result => "0041"// inequal test if two strings are equal
       

boolean s28 = Strman.inequal("a", "b");
        System.out.println("inequal:" + s28); // result => "true"// insert a substring into a string at the index position
       

String s29 = Strman.insert("fbar", "oo", 1);
        System.out.println("insert:" + s29); // result => "foobar"// leftPad pads the string from the left until the total length is n
       

String s30 = Strman.leftPad("1", "0", 5);
        System.out.println("leftPad:" + s30); // result => "00001"// rightPad pads the string from the right until the total length is n
       

String s30r = Strman.rightPad("1", "0", 5);
        System.out.println("rightPad:" + s30r); // result => "10000"// lastIndexOf This method returns the The index in the string object of the last occurrence of the call, searching backwards from the offset

 

int s31 = Strman.lastIndexOf("foobarfoobar", "F", false);
        System.out.println("lastIndexOf:" + s31); // result => "6"// leftTrim removes the leftmost part of the string all spaces
       

String s32 = Strman.leftTrim(" strman ");
        System.out.println("leftTrim:" + s32); // result => "strman "// rightTrim removes all spaces at the far right of the string
       

String s32r = Strman.rightTrim(" strman ");
        System.out.println("rightTrim:" + s32r); // result => " strman"// removeEmptyStrings removes empty strings from the string array
       

String[] s33 = Strman.removeEmptyStrings(new String[]{"aa", "", " ", "bb", "cc", null});
        System.out.println("removeEmptyStrings:" + Arrays.toString (s33));
        // result => "[aa, bb, cc]" // removeLeft gets the new string with the prefix removed (if it exists)
       

String s34 = Strman.removeLeft("foobar", "foo");
        System.out.println("removeLeft:" + s34); // result => "bar"// removeRight after removing the suffix (if it exists) new string of
       

String s34r = Strman.removeRight("foobar", "bar");
        System.out.println("removeRight:" + s34r); // result => "foo"// removeNonWords to get rid of non-character strings
       

String s35 = Strman.removeNonWords("foo&bar-");
        System.out.println("removeNonWords:" + s35); // result => "foobar"// removeSpaces removes all spaces
       

String s36 = Strman.removeSpaces(" str man ");
        System.out.println("removeSpaces:" + s36); // result => " strman"// repeat to get a new string with the given string and number of repetitions
       

String s37 = Strman.repeat("1", 3);
        System.out.println("repeat:" + s37); // result => "111"// reverse to get the reversed string
       

String s38 = Strman.reverse("foobar");
        System.out.println("reverse:" + s38); // result => "raboof"// safeTruncate Safely truncate a string without cutting half a word, it always returns the last complete word
       

String s39 = Strman.safeTruncate("A Javascript string manipulation library.", 19, "...");
        System.out.println("safeTruncate:" + s39); // result => "A Javascript... "// truncate less safe truncate string
       

String s40 = Strman.truncate("A Javascript string manipulation library.", 19, "...");
        System.out.println("truncate:" + s40); // result => "A Javascript str..."// htmlDecode 将html字符反转义
       

String s41 = Strman.htmlDecode("Ш");
        System.out.println("htmlDecode:" + s41); // result => "Ш"// htmlEncode 将html字符转义
       

String s42 = Strman.htmlEncode("Ш");
        System.out.println("htmlEncode:" + s42); // result => "Ш"// shuffle converts the given string into a string with random character order
       

String s43 = Strman.shuffle("shekhar");
        System.out.println("shuffle:" + s43); // result => "rhsheak"// slugify segment the string (with "-")
       

String s44 = Strman.slugify("foo bar");
        System.out.println("slugify:" + s44); // result => "foo-bar"// transliterate removes all non-valid characters like: á = > a
       

String s45 = Strman.transliterate("fóõ bár");
        System.out.println("transliterate:" + s45); // result => "foo bar"// surround the given "prefix" and "suffix" to wrap a string
       

String s46 = Strman.surround("div", "<", ">");
        System.out.println("surround:" + s46); // result => "<div>"// tail gets removed string after one character
       

String s47 = Strman.tail("foobar");
        System.out.println("tail:" + s47); // result => "oobar"// toCamelCase converted to camel case string
       

String s48 = Strman.toCamelCase("Camel Case");
        String s48_2 = Strman.toCamelCase("camel-case");
        System.out.println("tail:" + s48 + ", " + s48_2); // result => "camelCase, camelCase"// toStudlyCase 转成Studly式的字符串
       

String s49 = Strman.toStudlyCase("hello world");
        System.out.println("toStudlyCase:" + s49); // result => "HelloWorld"// toDecamelize 转成Decamelize式的字符串
       

String s50 = Strman.toDecamelize("helloWorld", null);
        System.out.println("toDecamelize:" + s50); // result => "hello world"// toKebabCase 转成Kebab式的字符串
       

String s51 = Strman.toKebabCase("hello World");
        System.out.println("toKebabCase:" + s51); // result => "hello-world"// toSnakeCase 转成Snake式的字符串
       

String s52 = Strman.toSnakeCase("hello world");
        System.out.println("toSnakeCase:" + s52); // result => "hello_world"

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326178212&siteId=291194637