public final class StringUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
CENTER_JUSTIFY
Center text.
|
static String[] |
JAVA_KEYWORDS |
static int |
LEFT_JUSTIFY
Justify text to the left side.
|
static String |
NON_TILDED_CHARS |
static int |
RIGHT_JUSTIFY
Justify text to the right side.
|
static String |
SPECIAL_CHARS |
static String |
TILDED_CHARS |
Modifier and Type | Method and Description |
---|---|
static String |
chomp(char[] charArray)
Given a character array, this method constructs a new string without
trailing carriage return or newline characters.
|
static String[] |
cutString(String text,
FontMetrics fontMetrics,
int maxWidth)
It returns an array of subchains of maximum length in pixels.
|
static String |
eliminateWordsShorterThan(String str,
int size)
Delete all the words of a string smaller that a given size, and the extra
blank characters
|
static String |
escapeQuotes(String str) |
static String |
fill(String str,
char ch,
int size)
Fill a string with chars, in order to grow to a given size.
|
static String |
fill(String str,
String strFill,
int size)
Fill a string repeating other string, in order to grow to a given size.
|
static String |
fill(String str,
String strFill,
int size,
boolean fillRight)
Fill a string repeating other string, in order to grow to a given size.
|
static String |
filterSQLString(String str)
Replace all the ocurrences of the char ' with '',
and add a ' at the start and the end of the string.
|
static String |
findFirst(String str,
String find)
Searches into a String for the prefix before the specified substring.
|
static String |
findLast(String str,
String find)
Search into a String for the suffix after the last occurrence of the
specified substring.
|
static String |
findRest(String str,
String find)
Search into a String for the suffix after the first occurrence of the
specified substring.
|
static String |
firstLow(String str)
Lower case the first character in a String.
|
static String |
firstUp(String str)
Upper case the first character in a String.
|
static String |
fixUnicodeCharacters(String name)
Replace special characters with simple characters
|
static String |
getStringFromTokens(Vector vector,
String delimiter)
Return a String who contains the strings in the Vector vector
separated by delimiter.
|
static Vector |
getTokensFromString(String str)
Return a vector with str divided in fragments.
|
static Vector |
getTokensFromString(String str,
String delimiter)
Return a vector with str divided in fragments, separated by
delimiter.
|
static String |
indentParagraph(String textToModify,
int indentSize)
Insert "indentSize" spaces before every line of textToModify.
|
static String |
indentParagraph(String textBefore,
String textToModify)
Deprecated.
Use indentParagraph(String,int) instead
|
static int |
indexOf(String str,
int fromIndex,
StringBuffer buf)
Returns the position of the first ocurrence of the substring into
the stringbuffer, starting at fromIndex, or -1 if does not ocurr.
|
static int |
indexOf(String str,
StringBuffer buf)
Returns the position of the first ocurrence of the substring into
the stringbuffer, or -1 if does not ocurr.
|
static boolean |
isJavaIdentifier(String str)
Checks if the specified string is a valid java identifier.
|
static boolean |
isJavaKeyword(String name)
Returns true if the given String is a Java keyword which will cause a
problem when used as a variable name.
|
static boolean |
isJavaPackage(String name)
Checks if the given package name is valid or not.
|
static String |
justify(String str,
int size,
int type)
Justify a string.
|
static String |
lowerFirstLetter(String str)
Converts the first letter to lower case.
|
static String |
lowerFirstUp(String str)
Upper case the first character in a String, lower the rest of the string.
|
static void |
main(String[] args) |
static String |
makeSQLString(String str)
Convert a string to SQL sentence string.
|
static int |
ocurrencesOf(String str,
char chr)
Get the number of ocurrences of a character into a string
|
static String |
parseASCIITemplate(String template,
Map params)
Parses an ASCII template that contains parameters like
[#param#] and replace them with the values associated
in params . |
static String |
parseASCIITemplate(String template,
Map params,
String leftMark,
String rightMark) |
static String |
parseASCIITemplate(String template,
Map params,
String leftMark,
String rightMark,
boolean nullifyNotFound) |
static String |
removeAll(String origStr,
String removeStr)
Remove all the ocurrences of a substring from a string
|
static String |
removeAll(String str,
String[] substr)
Remove all the ocurrences of a group of substring from a string
|
static String |
removeFirst(String origStr,
String removeStr)
Remove the first ocurrence of a substring from a string
|
static String |
repeat(String str,
int num)
Repeat a String n times.
|
static String |
replace(String origStr,
char oldChar,
String newStr)
Deprecated.
replaced by replaceAll()
|
static String |
replace(String origStr,
String oldStr,
String newStr)
Deprecated.
replaced by replaceAll()
|
static String |
replaceAll(String origStr,
char oldChar,
String newStr)
Replaces a character of a String with characters in the specified
new substring.
|
static String |
replaceAll(String str,
String[] in,
String[] out)
Replaces the characters in all substrings of a String with characters in
the specified array of substrings.
|
static String |
replaceAll(String str,
String[] in,
String[] out,
String beginDelim,
String endDelim)
Returns a String who replace Strings include into str,
which are into delimiters and known in in,
to corresponding String from out.
|
static String |
replaceAll(String origStr,
String oldStr,
String newStr)
Replaces the characters in a substring of a String with characters in
the specified new substring.
|
static String |
replaceAll(String str,
Vector in,
Vector out,
String beginDelim,
String endDelim)
Returns a String who replace Strings include into str,
which are into delimiters and known in in,
to corresponding String from out.
|
static String |
replaceFirst(String origStr,
String oldStr,
String newStr)
Replacing first ocurrence of oldStr in origStr with newStr
|
static Map |
replaceParamsValues(Map params,
String oldSubstring,
String newSubstring)
Replace all the occurences of oldSubstring with newSubstring in the
values of a parameter mapping structure
|
static String |
replaceUnicodeCharacters(String str)
Convert special characters in unicode characters
|
static String |
soundTrex(String original)
Soundtrex algorithm.
|
static String |
substring(String str,
int beginIndex,
int endIndex)
Return a new String that is a substring of this string.
|
static String |
subString(String str,
int beginIndex,
int endIndex)
Deprecated.
Use substring instead
|
static String |
toJavaClassName(String name)
Get a valid java class name for the given string.
|
static String |
toJavaFieldName(String name)
Get a valid java filed name for the given string.
|
static String |
toJavaIdentifier(String str)
Converts the given string to a Java valid identifier.
|
static String |
toJavaPackagePath(String packageName)
Converts the given Package name to it's corresponding Path.
|
static String |
trimLowerCase(String str)
Remove white space from both ends of this string and converts all of the
characters in this String to lower case.
|
static String |
trimUpperCase(String str)
Remove white space from both ends of this string and converts all of the
characters in this String to upper case.
|
static String |
upperFirstLetter(String str)
Converts the first letter to upper case.
|
public static final int LEFT_JUSTIFY
public static final int RIGHT_JUSTIFY
public static final int CENTER_JUSTIFY
public static final String SPECIAL_CHARS
public static final String TILDED_CHARS
public static final String NON_TILDED_CHARS
public static final String[] JAVA_KEYWORDS
public static String replace(String origStr, char oldChar, String newStr)
origStr
- string that contains the replaceable substringoldChar
- character to search in the orig StringnewStr
- substring of the new characterspublic static String replaceAll(String origStr, char oldChar, String newStr)
origStr
- string that contains the replaceable substringoldChar
- character to search in the orig StringnewStr
- substring of the new characterspublic static String replaceFirst(String origStr, String oldStr, String newStr)
origStr
- original stringoldStr
- substring to search in the orig StringnewStr
- new substringpublic static String replace(String origStr, String oldStr, String newStr)
origStr
- original stringoldStr
- substring to search in the orig StringnewStr
- new substringpublic static String replaceAll(String origStr, String oldStr, String newStr)
origStr
- original stringoldStr
- substring to search in the orig StringnewStr
- new substringpublic static String removeFirst(String origStr, String removeStr)
origStr
- original stringremoveStr
- substring to remove from the orig Stringpublic static String removeAll(String origStr, String removeStr)
origStr
- original stringremoveStr
- substring to remove from the orig Stringpublic static Map replaceParamsValues(Map params, String oldSubstring, String newSubstring)
params
- the parameters mapping structure that contains
pairs of attr -> valueoldSubstring
- the string to replacenewSubstring
- the new stringpublic static String parseASCIITemplate(String template, Map params)
[#param#]
and replace them with the values associated
in params
.
The substitution of [#param#]
is performed this
way:
params
contains a key named param
and
its associated value is a non-null
reference,
[#param#]
is substituted by the
result of applying toString()
to that reference.
param
in
params
or its associated value is null
,
[#param#]
is replaced with
the literal "null"
.
template
- The parametrized templateparams
- The parameters structurepublic static String parseASCIITemplate(String template, Map params, String leftMark, String rightMark)
template
- the parametrized templateparams
- the parameters structureleftMark
- the left delimiter of the parameters to replacerightMark
- the right delimiter of the parameters to replaceparseASCIITemplate(String,Map)
public static String parseASCIITemplate(String template, Map params, String leftMark, String rightMark, boolean nullifyNotFound)
template
- the parametrized templateparams
- the parameters structureleftMark
- the left delimiter of the parameters to replacerightMark
- the right delimiter of the parameters to replacenullifyNotFound
- if true, change the not found params to "null";
if false, don't changeparseASCIITemplate(String,Map)
public static int indexOf(String str, StringBuffer buf)
str
- substring to findbuf
- buffer to search intopublic static int indexOf(String str, int fromIndex, StringBuffer buf)
str
- substring to findfromIndex
- the index to start the search frombuf
- buffer to search intopublic static String repeat(String str, int num)
str
- String to repeatnum
- number times to repeatpublic static String firstUp(String str)
str
- String to manipulatepublic static String firstLow(String str)
str
- String to manipulatepublic static String lowerFirstUp(String str)
str
- String to manipulatepublic static String trimUpperCase(String str)
str
- String to manipulatepublic static String trimLowerCase(String str)
str
- String to manipulatepublic static String findFirst(String str, String find)
str
- String to manipulatefind
- String to find in strpublic static String findRest(String str, String find)
str
- String to manipulatefind
- String to find in strpublic static String findLast(String str, String find)
str
- String to manipulatefind
- String to find in strpublic static Vector getTokensFromString(String str, String delimiter)
str
- String to manipulatedelimiter
- String who delimiters the Strings into strpublic static Vector getTokensFromString(String str)
str
- String to manipulateIf str doesn't contain delimiter return a vector with one
element: str exactly.
public static String getStringFromTokens(Vector vector, String delimiter)
vector
- list of tokensdelimiter
- String who delimiters the Strings into strpublic static String subString(String str, int beginIndex, int endIndex)
substring(String,int,int)
public static String substring(String str, int beginIndex, int endIndex)
str
- Cadena de TextobeginIndex
- the begining index, inclusiveendIndex
- the ending index, exclusivepublic static String indentParagraph(String textBefore, String textToModify)
textBefore
- String where extract the spaces to inserttextToModify
- String to modifypublic static String indentParagraph(String textToModify, int indentSize)
textToModify
- string to indentindentSize
- number of spaces to insertpublic static String justify(String str, int size, int type)
str
- string to justifysize
- size of line to justify totype
- type of justify (LEFT_JUSTIFY, RIGHT_JUSTIFY or
CENTER_JUSTIFY)public static String removeAll(String str, String[] substr)
str
- original stringsubstr
- array of substrings to remove from the orig Stringpublic static String replaceAll(String str, String[] in, String[] out)
str
- original stringin
- substrings to search in the orig Stringout
- array of new substringspublic static String replaceAll(String str, Vector in, Vector out, String beginDelim, String endDelim)
str
- String to manipulatein
- Vector which contains strings to findout
- Vector which contains strings to replacebeginDelim
- String who delimiters the begin of the substrings
into strendDelim
- String who delimiters the end of the substrings
into strpublic static String replaceAll(String str, String[] in, String[] out, String beginDelim, String endDelim)
str
- String to manipulatein
- array of strings to findout
- array of strings to replacebeginDelim
- String who delimiters the begin of the substrings
into strendDelim
- String who delimiters the end of the substrings
into strIllegalArgumentException
- if beginDelim and endDelim are equalpublic static String eliminateWordsShorterThan(String str, int size)
str
- string to processsize
- size limitpublic static String filterSQLString(String str)
select * from tabla where nombre = 'Peter' and edad = 25 => select * from tabla where nombre = ''Peter'' and edad = 25
str
- Original Stringpublic static String makeSQLString(String str)
select * from tabla where nombre = 'Peter' and edad = 25 => 'select * from tabla where nombre = ''Peter'' and edad = 25'
str
- Original Stringpublic static String fill(String str, char ch, int size)
str
- original stringch
- char to fill withsize
- final size of the stringpublic static String fill(String str, String strFill, int size)
str
- original stringstrFill
- string to fill withsize
- final size of the stringpublic static String fill(String str, String strFill, int size, boolean fillRight)
str
- original stringstrFill
- string to fill withsize
- final size of the stringfillRight
- if true, the chars are appended by the right;
if false, by the leftpublic static String[] cutString(String text, FontMetrics fontMetrics, int maxWidth)
text
- original stringfontMetrics
- scrren font of text.maxWidth
- maximum width of subchains in pixels.public static String soundTrex(String original)
original
- String to analyzepublic static String chomp(char[] charArray)
charArray
- the character array to construct string frompublic static int ocurrencesOf(String str, char chr)
str
- string to search intochr
- character to foundpublic static String lowerFirstLetter(String str)
public static String upperFirstLetter(String str)
public static String toJavaIdentifier(String str)
str
- string to processpublic static boolean isJavaIdentifier(String str)
str
- (required).true
iff the specified string is a valid java
identifier.public static final boolean isJavaKeyword(String name)
name
- the name to checkpublic static boolean isJavaPackage(String name)
name
- name of package as String with periodspublic static String toJavaPackagePath(String packageName)
packageName
- the package name to convertpublic static String toJavaClassName(String name)
public static String toJavaFieldName(String name)
public static String fixUnicodeCharacters(String name)
name
- string to replacepublic static String replaceUnicodeCharacters(String str)
str
- string to convertpublic static void main(String[] args)
Copyright © 2012-2015 JBoss by Red Hat. All Rights Reserved.