public class TextUtils extends Object
| 构造器和说明 |
|---|
TextUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
htmlEncode(String s) |
static String |
htmlEncode(String s,
boolean encodeSpecialChars)
Escape html entity characters and high charact ers (eg "curvy" Word quotes).
|
static String |
join(String glue,
Collection pieces)
Join a Collection of Strings together.
|
static String |
join(String glue,
Iterator pieces)
Join an Iteration of Strings together.
|
static String |
join(String glue,
String[] pieces)
Join an array of Strings together.
|
static String |
noNull(String string)
Return
string, or "" if string
is null. |
static String |
noNull(String string,
String defaultString)
Return
string, or defaultString if
string is null or "". |
static boolean |
stringSet(String string)
Check whether
string has been set to
something other than "" or null. |
static boolean |
verifyUrl(String url)
Verify That the given String is in valid URL format.
|
public static final String htmlEncode(String s, boolean encodeSpecialChars)
s - the String to escape.encodeSpecialChars - if true high characters will be encode other wise not.public static final String join(String glue, Iterator pieces)
// get Iterator of Strings ("abc","def","123");
Iterator i = getIterator();
out.print( TextUtils.join(", ",i) );
// prints: "abc, def, 123"
glue - Token to place between Strings.pieces - Iteration of Strings to join.public static final String join(String glue, String[] pieces)
glue - Token to place between Strings.pieces - Array of Strings to join.join(String, Iterator)public static final String join(String glue, Collection pieces)
glue - Token to place between Strings.pieces - Collection of Strings to join.join(String, Iterator)public static final String noNull(String string, String defaultString)
string, or defaultString if
string is null or "".
Never returns null.
Examples:
// prints "hello" String s=null; System.out.println(TextUtils.noNull(s,"hello"); // prints "hello" s=""; System.out.println(TextUtils.noNull(s,"hello"); // prints "world" s="world"; System.out.println(TextUtils.noNull(s, "hello");
string - the String to check.defaultString - The default string to return if string is null or ""string if string is non-empty, and defaultString otherwisestringSet(String)public static final String noNull(String string)
string, or "" if string
is null. Never returns null.
Examples:
// prints 0 String s=null; System.out.println(TextUtils.noNull(s).length()); // prints 1 s="a"; System.out.println(TextUtils.noNull(s).length());
string - the String to checkpublic static final boolean stringSet(String string)
string has been set to
something other than "" or null.string - the String to checkpublic static final boolean verifyUrl(String url)
url - The url string to verify.Copyright © 2023 onecode. All rights reserved.