introduce
Strmen-java is a string processing tool that you can introduce into your project via maven. Strmen-java provides us with a very complete and powerful solution, using it to solve almost any string processing scenario.
use
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 are using Maven for project management, you only need to add the following dependencies to your pom.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.shekhargulati', name: 'strman', version: '0.2.0', ext: 'jar'){ transitive=true}Example
The following is an example of using Strman-java:
import strman.Strman; import java.util.Arrays; import java.util.Optional;/** * Testing of strman-java package* Created by blinkfox on 16/7/17. */public class StrmanTest { public static void main(String[] args) { // append append any number of strings after a string String s1 = Strman.append("f", "o", "o", "b", "a", "r"); System.out.println("append:" + s1); // result => "foobar" // prepend appends any number of strings before a string String s1pre = Strman.prepend("r", "f", "o", "o", "b", "a"); System.out.println("prepend:" + s1pre); // result => "foobar" // appendArray Appends elements in a string array 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 a negative number, it is fetched in reverse, and an exception is thrown afterwards. Optional<String> s3 = Strman.at("foobar", 3); System.out.println("at:" + s3.get()); // result => "b" // between Get an array of strings between the starting string and the ending string in a string String[] s4 = Strman.between("[abc], [def]", "[", "]"); System.out.println("between:" + Arrays.toString(s4)); // result => "[abc, def]" // chars Get the string array composed 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 Replace multiple consecutive spaces into one space String s6 = Strman.collapseWhitespace("foo bar"); System.out.println("chars:" + s6); // result => "foo bar" // contains Determine whether a string contains another string, the third parameter indicates whether the case of the string is sensitive to 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 Determine whether a string contains all elements in an array of strings 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 Determine whether a string contains any element in an array of strings boolean s11 = Strman.containsAny("foo bar", new String[]{"FOO", "BAR", "Test"}, false); System.out.println("containsAny:" + s11); // result => "true" // countSubstr long s12 = Strman.countSubstr("aaaAAAaaa", "aaa"); long s13 = Strman.countSubstr("aaaAAAaaa", "aaa", false, false); System.out.println("countSubstr:" + s12 + ", " + s13); // result => "2, 3" // endsWith Determine whether a string ends in 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 Make sure a string starts with a string. If not, append the string in front of it and return 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 Make sure a string starts with a string. If not, append the string in front of it and return the string result String s16r = Strman.ensureRight("foobar", "bar"); String s17r = Strman.ensureRight("fooBAR", "bar", false); System.out.println("ensureRight:" + s16r + ", " + s17r + ", " + s18r); // result => "foobar, foobar, fooBAR" // base64Encode Converts strings to Base64-encoded strings String s19 = Strman.base64Encode("strman"); System.out.println("base64Encode:" + s19); // result => "c3RybWFu" // binDecode Converts binary encoding (16-bit) to string characters String s20 = Strman.binDecode("0000000001000001"); System.out.println("binDecode:" + s20); // result => "A" // binEncode Convert string characters to binary encoding (16-bit) String s21 = Strman.binEncode("A"); System.out.println("binEncode:" + s21); // result => "000000000001000001" // decDecode Convert decimal encoding (5-bit) to string characters String s22 = Strman.decDecode("00065"); System.out.println("decDecode:" + s22); // result => "A" // decEncode Converts the string into decimal encoding (5-bit) String s23 = Strman.decEncode("A"); System.out.println("decEncode:" + s23); // result => "00065" // first Get the string from the string to the index n String s24 = Strman.first("foobar", 3); System.out.println("first:" + s24); // result => "foo" // last Get the string String String s24l = Strman.last("foobar", 3); System.out.println("last:" + s24l); // result => "bar" // head Get the first character of the string String s25 = Strman.head("foobar"); System.out.println("head:" + s25); // result => "f" // hexDecode Converts string characters into hex encoding (4-bit) String s26 = Strman.hexDecode("0041"); System.out.println("hexDecode:" + s26); // result => "A" // hexEncode Convert hex encoding (4-bit) into string characters String s27 = Strman.hexEncode("A"); System.out.println("hexEncode:" + s27); // result => "0041" // inequal Test whether two strings are equal boolean s28 = Strman.inequal("a", "b"); System.out.println("inequal:" + s28); // result => "true" // insert Insert substring at a certain index position of the string String s29 = Strman.insert("fbar", "oo", 1); System.out.println("insert:" + s29); // result => "foobar" // leftPad Complement 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 Complement 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 index in the last call string object that occurred in the specified value, searching backward from the offset int s31 = Strman.lastIndexOf("foobarfoobar", "F", false); System.out.println("lastIndexOf:" + s31); // result => "6" // leftTrim Removes all spaces on the leftmost string String s32 = Strman.leftTrim(" strman "); System.out.println("leftTrim:" + s32); // result => "strman " // rightTrim Remove all spaces on the rightmost string String s32r = Strman.rightTrim(" strman "); System.out.println("rightTrim:" + s32r); // result => " strman" // removeEmptyStrings Remove empty strings in string array String[] s33 = Strman.removeEmptyStrings(new String[]{"aa", "", " ", "bb", "cc", null}); System.out.println("removeEmptyStrings:" + Arrays.toString(s33)); // result => "[aa, bb, cc]" // removeLeft Get the new string after removing the prefix (if it exists) String s34 = Strman.removeLeft("foobar", "foo"); System.out.println("removeLeft:" + s34); // result => "bar" // removeRight Get the new string after removing the suffix (if it exists) String s34r = Strman.removeRight("foobar", "bar"); System.out.println("removeRight:" + s34r); // result => "foo" // removeNonWords Get rid of the string that is not a character String s35 = Strman.removeNonWords("foo&bar-"); System.out.println("removeNonWords:" + s35); // result => "foobar" // removeSpaces Remove all spaces String s36 = Strman.removeSpaces(" str man "); System.out.println("removeSpaces:" + s36); // result => " strman" // repeat Get the new string for the given string and number of repetitions String s37 = Strman.repeat("1", 3); System.out.println("repeat:" + s37); // result => "111" // reverse Get the reversed string String s38 = Strman.reverse("foobar"); System.out.println("reverse:" + s38); // result => "raboof" // safeTruncate Safe truncate string, without cutting half of a word, it always returns the last full word String s39 = Strman.safeTruncate("A Javascript string manipulation library.", 19, "..."); System.out.println("safeTruncate:" + s39); // result => "A Javascript..." // truncate String s40 = Strman.truncate("A Javascript string manipulation library.", 19, "..."); System.out.println("truncate:" + s40); // result => "A Javascript str..." // htmlDecode Inversely escape html characters String s41 = Strman.htmlDecode("Ш"); System.out.println("htmlDecode:" + s41); // result => "Ш" // htmlEncode escape html characters String s42 = Strman.htmlEncode("Ш"); System.out.println("htmlEncode:" + s42); // result => "Ш" // shuffle Convert the given string into a string in random character order String s43 = Strman.shuffle("shekhar"); System.out.println("shuffle:" + s43); // result => "rhshheak" // slugify segments the string (using "-" segments) String s44 = Strman.slugify("foo bar"); System.out.println("slugify:" + s44); // result => "foo-bar" // translateate Delete all non-valid characters, such as: á => a String s45 = Strman.transliterate("fóõ bár"); System.out.println("transliterate:" + s45); // result => "foo bar" // surround The given "prefix" and "suffix" are used to wrap a string String s46 = Strman.surround("div", "<", ">"); System.out.println("surround:" + s46); // result => "<div>" // tail Get the string after removing the first character String s47 = Strman.tail("foobar"); System.out.println("tail:" + s47); // result => "oobar" // toCamelCase converts to camel-like 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 Convert to Studly-style string String s49 = Strman.toStudlyCase("hello world"); System.out.println("toStudlyCase:" + s49); // result => "HelloWorld" // toDecamelize to Decamelize String String s50 = Strman.toDecamelize("helloWorld", null); System.out.println("toDecamelize:" + s50); // result => "hello world" // toKebabCase to Kebab-style String String s51 = Strman.toKebabCase("hello World"); System.out.println("toKebabCase:" + s51); // result => "hello-world" // toSnakeCase to Snake String String String s52 = Strman.toSnakeCase("hello world"); System.out.println("toSnakeCase:" + s52); // result => "hello_world" }}Summarize
The above is the entire content of this article. I hope it can help you study or work. If you have any questions, you can leave a message to communicate.