導入
Strmen-Javaは、Mavenを介してプロジェクトに紹介できる文字列処理ツールです。 Strmen-Javaは、非常に完全で強力なソリューションを提供し、それを使用してほぼすべての文字列処理シナリオを解決します。
使用
JavaアプリケーションでStrman-Javaを使用するために、このパッケージをダウンロードして、プロジェクトのLIBディレクトリに追加できます。プロジェクト管理にMavenを使用している場合、 pom.xmlに次の依存関係を追加するだけが必要です。
<Dependency> <GroupId> com.Shekhargulati </groupId> <ArtifActid> strman </artifactid> <バージョン> 0.2.0 </version> <type> jar </type> </dependency>
Gradleユーザーの場合は、次のコードをbuild.gradleファイルに追加します。
コンパイル(グループ: 'com.shekhargulati'、name: 'strman'、バージョン: '0.2.0'、ext: 'jar'){transitive = true}例
以下は、Strman-Javaを使用する例です。
インポートstrman.strman; java.util.arraysをインポートします。 java.util.optional;/*** 16/7/17にBlinkfoxによって作成されたStrman-Javaパッケージのテスト。 */public class strmantest {public static void main(string [] args){//文字列s1 = strman.append( "f"、o "、" o "、" b "、" a "、" r ")の後に文字列s1 = strman.append(" f "、o"、 "o"、 "b"、 ")を追加します。 System.out.println( "append:" + s1); // result => "foobar" // string string s1pre = strman.prend( "r"、 "f"、 "o"、 "o"、 "b"、 "a")の前に任意の数の文字列を追加します。 system.out.println( "prepend:" + s1pre); // result => "foobar" // appendArrayは、文字列アレイ文字列s2 = strman.appendarray( "f"、new String [] {"o"、 "o"、 "b"、 "a"、 "r"})に要素を追加します。 System.out.println( "append:" + s2); // result => "foobar" //文字列のインデックスに従って対応する文字を取得します。インデックスが負の数である場合、それは逆にフェッチされ、その後例外がスローされます。オプション<string> s3 = strman.at( "foobar"、3); system.out.println( "at:" + s3.get()); // result => "b" // string string [] s4 = strman.bet( "[abc]、[def]" "、" ["、"] ")の開始文字列とエンディング文字列の間に文字列の配列を取得します。 system.out.println( "bety:" + arrays.toString(s4)); // result => "[abc、def]" // chars string string [] s5 = strman.chars( "title")のすべての文字で構成される文字列アレイを取得します。 system.out.println( "chars:" + arrays.tostring(s5)); // result => "[t、i、t、l、e]" // collapsewhiteSpace複数の連続したスペースを1つのスペース文字列s6 = strman.collapsewhitespace( "foo bar"); System.out.println( "chars:" + s6); // result => "foo bar" //文字列に別の文字列が含まれているかどうかを決定します。3番目のパラメーターは、文字列の場合が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文字列に一連の文字列にすべての要素が含まれるかどうかを判断します。 boolean s10 = strman.containsall( "foo bar"、new String [] {"foo"、 "bar"}、false); system.out.println( "containsall:" + s9 + "、" + s10); // result => "true、true" // containsing文字列に一連の文字列に任意の要素が含まれているかどうかを決定します。 system.out.println( "containsany:" + s11); // result => "true" // countsubstr long s12 = strman.countsubstr( "aaaaaaaaa"、 "aaa"); long s13 = strman.countsubstr( "aaaaaaaaaa"、 "aaa"、false、false); System.out.println( "countSubstr:" + s12 + "、" + s13); // result => "2、3" // endswith文字列が文字列で終わるかどうかを決定します。 boolean s15 = strman.endswith( "foo bar"、 "bar"、false); System.out.println( "endswith:" + s14 + "、" + s15); // result => "true、true" // ensureleft文字列が文字列で始まることを確認します。そうでない場合は、その前に文字列を追加して、文字列結果文字列s16 = strman.ensureleft( "foobar"、 "foo")を返します。文字列s17 = strman.ensurelefeleft( "bar"、 "foo");文字列s18 = strman.ensurelefe( "foobar"、 "foo"、false); System.out.println( "ensurelefet:" + s16 + "、" + s17 + "、" + s18); // result => "foobar、foobar、foobar" // ensureright文字列が文字列で始まることを確認します。そうでない場合は、その前に文字列を追加し、文字列結果文字列s16r = strman.ensureright( "foobar"、 "bar")を返します。文字列S17r = strman.ensureright( "foobar"、 "bar"、false); System.out.println( "ensureright:" + s16r + "、" + s17r + "、" + s18r); // result => "foobar、foobar、foobar" // base64encode文字列をbase64エンコード文字列s19 = strman.base64encode( "strman"); System.out.println( "base64encode:" + s19); // result => "c3rybwfu" // bindecodeはバイナリエンコード(16ビット)を文字列string s20 = strman.bindecode( "0000000001000001")に変換します。 system.out.println( "bindecode:" + s20); // result => "a" // binencode文字列文字をバイナリエンコード(16ビット)文字列s21 = strman.binencode( "a"); System.out.println( "binencode:" + s21); // result => "000000000001000001" // decdecode decdecode decimal encoding(5ビット)を文字列文字列s22 = strman.decdecode( "00065"); System.out.println( "decdecode:" + s22); // result => "a" // decencodeは文字列を小数点エンコード(5ビット)文字列s23 = strman.decencode( "a")に変換します。 system.out.println( "decencode:" + s23); // result => "00065" //最初に文字列をインデックスn文字列s24 = strman.first( "foobar"、3); system.out.println( "first:" + s24); // result => "foo" // last get string string string string s24l = strman.last( "foobar"、3); System.out.println( "last:" + s24l); // result => "bar" // head文字列の最初の文字文字列s25 = strman.head( "foobar"); System.out.println( "head:" + s25); // result => "f" // hexdecode文字列文字をhexエンコード(4ビット)文字列s26 = strman.hexdecode( "0041"); System.out.println( "hexDecode:" + s26); // result => "a" // hexencode hexエンコード(4ビット)を文字列文字弦s27 = strman.hexencode( "a"); system.out.println( "hexencode:" + s27); // result => "0041" // 2つの文字列が等しいかどうかの不平等テストブールs28 = strman.inequal( "a"、 "b"); System.out.println( "inequal:" + s28); // result => "true" //文字列s29 = strman.insert( "fbar"、 "oo"、1)の特定のインデックス位置にサブストリングを挿入します。 system.out.println( "insert:" + s29); // result => "foobar" //左パッドは、左から文字列を補完します。総長がn string s30 = strman.leftpad( "1"、 "0"、5); system.out.println( "leftpad:" + s30); // result => "00001" //右パッド総長がn string s30r = strman.rightpad( "1"、 "0"、5)になるまで、右から文字列を補完します。 system.out.println( "rightpad:" + s30r); // result => "10000" // lastindexofこのメソッドは、指定された値で発生した最後の呼び出し文字列オブジェクトのインデックスを返し、オフセットint s31 = strman.lastindexof( "foobarfoobar"、 "f"、false)から後方に検索します。 System.out.println( "lastIndexof:" + s31); // result => "6" // lefttrimは、左端の文字列s32 = strman.lefttrim( "strman")のすべてのスペースを削除します。 System.out.println( "lefttrim:" + s32); // result => "strman" //右トリム右端の文字列上のすべてのスペースを削除s32r = strman.righttrim( "strman"); System.out.println( "righttrim:" + s32r); // result => "strman" // remofemptyStrings string array string [] s33 = strman.removeemptystrings(new String [] {"aa"、 ""、 ""、 "bb"、 "cc"、null})で空の文字列を削除します。 system.out.println( "removerEmptyStrings:" + arrays.toString(s33)); // result => "[aa、bb、cc]" // removeleftプレフィックスを削除した後に新しい文字列を取得します(存在する場合)string s34 = strman.removeleft( "foobar"、 "foo"); System.out.println( "Removeleft:" + s34); // result => "bar" // removeright接尾辞を削除した後、新しい文字列を取得します(存在する場合)文字列s34r = strman.removeright( "foobar"、 "bar"); System.out.println( "Removeright:" + s34r); // result => "foo" // removenonwords文字列ではない文字列を取り除きますs35 = strman.removenonwords( "foo&bar-"); system.out.println( "removenonwords:" + s35); // result => "foobar" //すべてのスペースを削除するすべてのスペース文字列s36 = strman.removespaces( "strman"); System.out.println( "removespaces:" + s36); // result => "strman" //繰り返し、指定された文字列と繰り返しの数の新しい文字列を取得し、文字列s37 = strman.repeat( "1"、3); System.out.println( "Repeat:" + S37); // result => "111" //逆逆文字列文字列s38 = strman.reverse( "foobar"); System.out.println( "Reverse:" + S38); // result => "raboof" // SafetRuncate SafeTruncate Safe Truncate String、単語の半分を切ることなく、常に最後の完全な単語文字列s39 = strman.safetruncate( "a javascript string操作ライブラリ。"、19、 "..."); System.out.println( "Safetruncate:" + s39); // result => "a javascript ..." // truncate string s40 = strman.truncate( "javascript文字列操作ライブラリ。"、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 => "ш" //シャッフル指定された文字列をランダムな文字列で文字列に変換しますstring s43 = strman.shuffle( "shekhar"); System.out.println( "shuffle:" + s43); // result => "rhshheak" // slugifyセグメント文字列( " - "セグメントを使用)文字列s44 = strman.slugify( "foo bar"); System.out.println( "slugify:" + s44); // result => "foo-bar" // translateate次のようなすべての非検証文字を削除します。 System.out.println( "erlerterate:" + s45); // result => "foo bar" //指定された "prefix"と "suffix"は、文字列s46 = strman.surround( "div"、 "<"、 ">")をラップするために使用されます。 System.out.println( "サラウンド:" + s46); // result => "<div>" //テール最初の文字文字列s47 = strman.tail( "foobar")を削除した後、文字列を取得します。 System.out.println( "Tail:" + S47); // result => "ooobar" // tocamelcaseはキャメルのような文字列s48 = strman.tocamelcase( "camel case")に変換します。文字列S48_2 = strman.tocamelcase( "camel-case"); System.out.println( "Tail:" + S48 + "、" + S48_2); // result => "camelcase、camelcase" // tostudlycaseは、スタッドスタイルの文字列s49 = strman.tostudlycase( "hello world")に変換します。 System.out.println( "tostudlycase:" + s49); // result => "helloworld" // todecamelize string string s50 = strman.todecamelize( "helloworld"、null); System.out.println( "todecamelize:" + s50); // result => "hello world" // tokebabcase to kebabスタイルの文字列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"}}要約します
上記は、この記事のコンテンツ全体です。勉強や仕事に役立つことを願っています。ご質問がある場合は、メッセージを残してコミュニケーションをとることができます。