Use of stringutils tool class

Source: Internet
Author: User
Use of the stringutils tool Class 1. Convert arrays into strings:
1. Convert the characters in the array into a string
Converts a character in an array to a string.

@ Param strtoconv: the string to be converted. It is separated by commas by default.
@ Return returns a string.
String [3] S = {"A", "B", "C "}
Stringutil. convstring (S) = "A, B, C"
2. Static Public String converstring (string strtoconv)
@ Param strtoconv: the string to be converted,
@ Param Conv separator, separated by commas by default
@ Return returns a string.

String [3] S = {"A", "B", "C "}
Stringutil. convstring (S, "@") = "A @ B @ C"
Static Public String converstring (string strtoconv, string Conv)

Ii. null value detection:
3,

Checks if a string is empty ("") or null.

Checks whether a string is empty and spaces are not empty. Stringutils. isempty (null) = true stringutils. isempty ("") = true stringutils. isempty ("") = false stringutils. isempty ("Bob") = false stringutils. isempty ("Bob") = false

Note: This method changed in Lang version 2.0.

It no longer trims the string.
That functionality is available in isblank ().

@ Param STR the string to check, may be null
@ Return true if the string is empty or null
Public static Boolean isempty (string Str)

3. Non-empty processing:
4,
Checks if a string is not empty ("") and not null.

Determines whether a string is not empty and spaces are not empty.Stringutils. isnotempty(Null) = falseStringutils. isnotempty("") = FalseStringutils. isnotempty("") = TrueStringutils. isnotempty("Bob") = trueStringutils. isnotempty("Bob") = true

@ Param STR the string to check, may be null
@ Return true if the string is not empty and not null
Public static Boolean isnotempty (string Str)

5,

Checks if a string is not empty (""), not null and not whitespace only.

Determines whether a string is not empty and spaces are empty. stringutils. isnotblank (null) = false stringutils. isnotblank ("") = false stringutils. isnotblank ("") = false stringutils. isnotblank ("Bob") = true stringutils. isnotblank ("Bob") = true

@ Param STR the string to check, may be null
@ Return true if the string is
Not empty and not null and not whitespace
@ Since 2.0
Public static Boolean isnotblank (string Str)

4. Space Processing
6,
Removes control characters (char <= 32) from both

Ends of this string, handling null by returning
Null.

The string is trimmed using {@ link string # trim ()}.

Trim removes start and end characters <= 32.
To strip whitespace use {@ link // strip (string )}.

To trim your choice of characters, use

{@ Link // strip (string, string)} methods.

Format a space in a string, with non-null Judgment Processing; stringutils. trim (null) = NULL stringutils. trim ("") = "" stringutils. trim ("") = "" stringutils. trim ("ABC") = "ABC" stringutils. trim ("ABC") = "ABC"

@ Param STR the string to be trimmed, may be null
@ Return the trimmed string, null if Null String Input
Public static string trim (string Str)

7,

Removes control characters (char <= 32) from both

Ends of this string returning null if the string is
Empty ("") after the trim or if it is null.

The string is trimmed using {@ link string # trim ()}.

Trim removes start and end characters <= 32.
To strip whitespace use {@ link/striptonull (string )}.

Format a space in a string. If it is null, null is returned. stringutils. trimtonull (null) = NULL stringutils. trimtonull ("") = NULL stringutils. trimtonull ("") = NULL stringutils. trimtonull ("ABC") = "ABC" stringutils. trimtonull ("ABC") = "ABC"

@ Param STR the string to be trimmed, may be null
@ Return the trimmed string,
Null if only chars <= 32, empty or Null String Input
@ Since 2.0
Public static string trimtonull (string Str)

8,

Removes control characters (char <= 32) from both

Ends of this string returning an empty string ("") if the string
Is empty ("") after the trim or if it is null.

The string is trimmed using {@ link string # trim ()}.

Trim removes start and end characters <= 32.
To strip whitespace use {@ link/striptoempty (string )}.

Format the space in a string. If it is null, the system returns ""; stringutils. trimtoempty (null) = "" stringutils. trimtoempty ("") = "" stringutils. trimtoempty ("") = "" stringutils. trimtoempty ("ABC") = "ABC" stringutils. trimtoempty ("ABC") = "ABC"

@ Param STR the string to be trimmed, may be null
@ Return the trimmed string, or an empty string if null Input
@ Since 2.0
Public static string trimtoempty (string Str)

V. String comparison:
9,
Compares two strings, returning true if they are equal.

Nulls are handled without exceptions. Two null

References are considered to be equal. The comparison is case sensitive.

Checks whether two strings are equal and whether non-empty strings are processed. Stringutils. equals (null, null) = true stringutils. equals (null, "ABC") = false stringutils. equals ("ABC", null) = false stringutils. equals ("ABC", "ABC") = true stringutils. equals ("ABC", "ABC") = false

@ Param str1 the first string, may be null
@ Param str2 the second string, may be null
@ Return true if the strings are equal, case sensitive, or
Both null
@ See java. Lang. string # equals (object)
Public static Boolean equals (string str1, string str2)

10,

Compares two strings, returning true if they are equal ignoring

The case.

Nulls are handled without exceptions. Two null

References are considered equal. comparison is case insensitive.

Checks whether two strings are equal and whether non-empty strings are processed. Case Insensitive stringutils. required signorecase (null, null) = true stringutils. required signorecase (null, "ABC") = false stringutils. required signorecase ("ABC", null) = false stringutils. required signorecase ("ABC", "ABC") = true stringutils. required signorecase ("ABC", "ABC") = true

@ Param str1 the first string, may be null
@ Param str2 the second string, may be null
@ Return true if the strings are equal, case insensitive, or
Both null
@ See java. Lang. string # define signorecase (string)
Public static Boolean inclusignorecase (string str1, string str2)

6. indexof Processing
11,

Finds the first index within a string, handling null.

This method uses {@ link string # indexof (string )}.

A null string will return-1.

Returns the position of the string to be searched. A non-empty string is used to process stringutils. indexof (null, *) =-1 stringutils. indexof (*, null) =-1 stringutils. indexof ("", "") = 0 stringutils. indexof ("aabaabaa", "A") = 0 stringutils. indexof ("aabaabaa", "B") = 2 stringutils. indexof ("aabaabaa", "AB") = 1 stringutils. indexof ("aabaabaa", "") = 0

@ Param STR the string to check, may be null
@ Param searchstr the string to find, may be null
@ Return the first index of the search string,
-1 if no match or Null String Input
@ Since 2.0
Public static int indexof (string STR, string searchstr)

12,

Finds the first index within a string, handling null.

This method uses {@ link string # indexof (string, INT )}.

A null string will return-1.

A negative start position is treated as zero.
An empty ("") search string always matches.
A start position greater than the string length only matches
An empty search string.

Returns the position of the string to be searched at the specified position. If it is not null, stringutils is processed. indexof (null, *, *) =-1 stringutils. indexof (*, null, *) =-1 stringutils. indexof ("", "", 0) = 0 stringutils. indexof ("aabaabaa", "A", 0) = 0 stringutils. indexof ("aabaabaa", "B", 0) = 2 stringutils. indexof ("aabaabaa", "AB", 0) = 1 stringutils. indexof ("aabaabaa", "B", 3) = 5 stringutils. indexof ("aabaabaa", "B", 9) =-1 stringutils. indexof ("aabaabaa", "B",-1) = 2 stringutils. indexof ("aabaabaa", "", 2) = 2 stringutils. indexof ("ABC", "", 9) = 3

@ Param STR the string to check, may be null
@ Param searchstr the string to find, may be null
@ Param startpos the start position, negative treated as zero
@ Return the first index of the search string,
-1 if no match or Null String Input
@ Since 2.0
Public static int indexof (string STR, string searchstr, int startpos)

VII. substring processing:
13,
Gets a substring from the specified string avoiding exceptions.

A negative start position can be used to start n

Characters from the end of the string.

A null string will return null.

An empty ("") string will return "".

Returns all stringutils characters in the string starting at the specified position. substring (null, *) = NULL stringutils. substring ("", *) = "" stringutils. substring ("ABC", 0) = "ABC" stringutils. substring ("ABC", 2) = "C" stringutils. substring ("ABC", 4) = "" stringutils. substring ("ABC",-2) = "BC" stringutils. substring ("ABC",-4) = "ABC"

@ Param STR the string to get the substring from, may be null
@ Param start the position to start from, negative means
Count back from the end of the string by this character characters
@ Return substring from start position, null if Null String Input
Public static string substring (string STR, int start)

14,

Gets a substring from the specified string avoiding exceptions.

A negative start position can be used to start/end n

Characters from the end of the string.

The returned substring starts with the character in the start

Position and ends before the end position. All postion counting is
Zero-based -- I. e., to start at the beginning of the string use
Start = 0. Negative start and end positions can be used
Specify offsets relative to the end of the string.

If start is not strictly to the left of end ,""

Is returned.

Returns the substring stringutils from the starting position to the ending position. substring (null, *, *) = NULL stringutils. substring ("", *, *) = ""; stringutils. substring ("ABC", 0, 2) = "AB" stringutils. substring ("ABC", 2, 0) = "" stringutils. substring ("ABC", 2, 4) = "C" stringutils. substring ("ABC", 4, 6) = "" stringutils. substring ("ABC", 2, 2) = "" stringutils. substring ("ABC",-2,-1) = "B" stringutils. substring ("ABC",-4, 2) = "AB"

@ Param STR the string to get the substring from, may be null
@ Param start the position to start from, negative means
Count back from the end of the string by this character characters
@ Param end the position to end at (exclusive), negative means
Count back from the end of the string by this character characters
@ Return substring from start position to end positon,
Null if Null String Input
Public static string substring (string STR, int start, int end)

15. substringafter/substringbefore (substring processing before and after:

Gets the substring before the first occurance of a separator.

The separator is not returned.

A Null String input will return null.

An empty ("") string input will return the empty string.
A null separator will return the input string.

Returns all stringutils characters before the specified string. substringbefore (null, *) = NULL stringutils. substringbefore ("", *) = "" stringutils. substringbefore ("ABC", "A") = "" stringutils. substringbefore ("abcba", "B") = "A" stringutils. substringbefore ("ABC", "C") = "AB" stringutils. substringbefore ("ABC", "D") = "ABC" stringutils. substringbefore ("ABC", "") = "" stringutils. substringbefore ("ABC", null) = "ABC"

@ Param STR the string to get a substring from, may be null
@ Param separator the string to search for, may be null
@ Return the substring before the first occurance of the separator,
Null if Null String Input
@ Since 2.0
Public static string substringbefore (string STR, string separator)

16,

Gets the substring after the first occurance of a separator.

The separator is not returned.

A Null String input will return null.

An empty ("") string input will return the empty string.
A null separator will return the empty string if
Input string is not null.

Returns all stringutils characters after the specified string. substringafter (null, *) = NULL stringutils. substringafter ("", *) = "" stringutils. substringafter (*, null) = "" stringutils. substringafter ("ABC", "A") = "BC" stringutils. substringafter ("abcba", "B") = "CBA" stringutils. substringafter ("ABC", "C") = "" stringutils. substringafter ("ABC", "D") = "" stringutils. substringafter ("ABC", "") = "ABC"

@ Param STR the string to get a substring from, may be null
@ Param separator the string to search for, may be null
@ Return the substring after the first occurance of the separator,
Null if Null String Input
@ Since 2.0
Public static string substringafter (string STR, string separator)

17,

Gets the substring before the last occurance of a separator.

The separator is not returned.

A Null String input will return null.

An empty ("") string input will return the empty string.
An empty or null separator will return the input string.

Returns all stringutils characters before the last specified string. substringbeforelast (null, *) = NULL stringutils. substringbeforelast ("", *) = "" stringutils. substringbeforelast ("abcba", "B") = "ABC" stringutils. substringbeforelast ("ABC", "C") = "AB" stringutils. substringbeforelast ("A", "A") = "" stringutils. substringbeforelast ("A", "Z") = "A" stringutils. substringbeforelast ("A", null) = "A" stringutils. substringbeforelast ("A", "") = ""

@ Param STR the string to get a substring from, may be null
@ Param separator the string to search for, may be null
@ Return the substring before the last occurance of the separator,
Null if Null String Input
@ Since 2.0
Public static string substringbeforelast (string STR, string separator)

18,

Gets the substring after the last occurance of a separator.

The separator is not returned.

A Null String input will return null.

An empty ("") string input will return the empty string.
An empty or null separator will return the empty string if
The input string is not null.

Returns all stringutils characters after the last specified string. substringafterlast (null, *) = NULL stringutils. substringafterlast ("", *) = "" stringutils. substringafterlast (*, "") = "" stringutils. substringafterlast (*, null) = "" stringutils. substringafterlast ("ABC", "A") = "BC" stringutils. substringafterlast ("abcba", "B") = "A" stringutils. substringafterlast ("ABC", "C") = "" stringutils. substringafterlast ("A", "A") = "" stringutils. substringafterlast ("A", "Z") = ""

@ Param STR the string to get a substring from, may be null
@ Param separator the string to search for, may be null
@ Return the substring after the last occurance of the separator,
Null if Null String Input
@ Since 2.0
Public static string substringafterlast (string STR, string separator)

8. Replacing (string replacement)
19,
Replaces all occurances of a string within another string.

A null reference passed to this method is a no-op.

Replace the specified stringutils string with the specified string. replace (null, *, *) = NULL stringutils. replace ("", *, *) = "" stringutils. replace ("ABA", null, null) = "ABA" stringutils. replace ("ABA", null, null) = "ABA" stringutils. replace ("ABA", "A", null) = "ABA" stringutils. replace ("ABA", "A", "") = "ABA" stringutils. replace ("ABA", "A", "Z") = "ZBZ"

@ Param text to search and replace in, may be null
@ Param repl the string to search for, may be null
@ Param with the string to replace with, may be null
@ Return the text with any replacements processed,
Null if Null String Input
@ See # Replace (string text, string repl, string with, int max)
Public static string Replace (string text, string repl, string)

20,

Replaces a string with another string inside a larger string,

For the first max values of the search string.

A null reference passed to this method is a no-op.

Replace the stringutils string of the original string with the maximum value of the specified string. replace (null, *) = NULL stringutils. replace ("", *) = "" stringutils. replace ("abaa", null, null, 1) = "abaa" stringutils. replace ("abaa", null, null, 1) = "abaa" stringutils. replace ("abaa", "A", null, 1) = "abaa" stringutils. replace ("abaa", "A", "", 1) = "abaa" stringutils. replace ("abaa", "A", "Z", 0) = "abaa" stringutils. replace ("abaa", "A", "Z", 1) = "zbaa" stringutils. replace ("abaa", "A", "Z", 2) = "zbza" stringutils. replace ("abaa", "A", "Z",-1) = "zbzz"

@ Param text to search and replace in, may be null
@ Param repl the string to search for, may be null
@ Param with the string to replace with, may be null
@ Param Max maximum number of values to replace, or-1 if no maximum
@ Return the text with any replacements processed,
Null if Null String Input
Public static string Replace (string text, string repl, string with, int max)

9. Case conversion (case-sensitive conversion)
21,

Converts a string to upper case as per {@ link string # touppercase ()}.

A null input string returns NULL.

Convert a string to uppercase stringutils. uppercase (null) = NULL stringutils. uppercase ("") = "" stringutils. uppercase ("ABC") = "ABC"

@ Param STR the string to upper case, may be null
@ Return the upper cased string, null if Null String Input
Public static string uppercase (string Str) 22,

Converts a string to lower case as per {@ link string # tolowercase ()}.

A null input string returns NULL.

Convert a string to lowercase stringutils. lowercase (null) = NULL stringutils. lowercase ("") = "" stringutils. lowercase ("ABC") = "ABC"

@ Param STR the string to lower case, may be null
@ Return the lower cased string, null if Null String Input
Public static string lowercase (string Str) 23,

Capitalizes a string changing the first letter to Title case

Per {@ link character # totitlecase (char)}. No other letters are changed.

For a word based alorithm, see {@ link/wordutils # capitalize (string )}.

A null input string returns NULL.

Stringutils. capitalize (null) = NULL stringutils. capitalize ("") = "" stringutils. capitalize ("cat") = "cat" stringutils. capitalize ("cat") = "cat"

@ Param STR the string to capitalize, may be null
@ Return the capitalized string, null if Null String Input
@ See/wordutils # capitalize (string)
@ See/uncapitalize (string)
@ Since 2.0
Uppercase letters
Public static string capitalize (string Str)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.