public class StringGroovyMethods extends DefaultGroovyMethodsSupport
public static String reverse(String self)
provides a reverse()
method for String
.
NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.
Constructor and Description |
---|
StringGroovyMethods() |
Modifier and Type | Method and Description |
---|---|
static boolean |
asBoolean(java.lang.CharSequence string)
Coerce a string (an instance of CharSequence) to a boolean value.
|
static boolean |
asBoolean(java.util.regex.Matcher matcher)
Coerce a Matcher instance to a boolean value.
|
static <T> T |
asType(java.lang.CharSequence self,
java.lang.Class<T> c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the
as operator. |
static <T> T |
asType(GString self,
java.lang.Class<T> c)
Converts the GString to a File, or delegates to the default
DefaultGroovyMethods.asType(Object, Class) |
static <T> T |
asType(java.lang.String self,
java.lang.Class<T> c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the
as operator. |
static java.util.regex.Pattern |
bitwiseNegate(java.lang.CharSequence self)
Turns a CharSequence into a regular expression Pattern
|
static java.util.regex.Pattern |
bitwiseNegate(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
capitalize(java.lang.CharSequence self)
Convenience method to capitalize the first letter of a CharSequence
(typically the first letter of a word).
|
static java.lang.String |
capitalize(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
center(java.lang.CharSequence self,
java.lang.Number numberOfChars)
Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character around it as many times as needed so that it remains centered.
|
static java.lang.String |
center(java.lang.CharSequence self,
java.lang.Number numberOfChars,
java.lang.CharSequence padding)
Pad a CharSequence to a minimum length specified by numberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.
|
static java.lang.String |
center(java.lang.String self,
java.lang.Number numberOfChars)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
center(java.lang.String self,
java.lang.Number numberOfChars,
java.lang.String padding)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
collectReplacements(java.lang.String orig,
Closure<java.lang.String> transform)
Iterate through this String a character at a time collecting either the
original character or a transformed replacement String.
|
static boolean |
contains(java.lang.CharSequence self,
java.lang.CharSequence text)
Provide an implementation of contains() like
Collection.contains(Object) to make CharSequences more polymorphic. |
static boolean |
contains(java.lang.String self,
java.lang.String text)
Deprecated.
Use the CharSequence version
|
static int |
count(java.lang.CharSequence self,
java.lang.CharSequence text)
Count the number of occurrences of a sub CharSequence.
|
static int |
count(java.lang.String self,
java.lang.String text)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
denormalize(java.lang.CharSequence self)
Return a CharSequence with lines (separated by LF, CR/LF, or CR)
terminated by the platform specific line separator.
|
static java.lang.String |
denormalize(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.CharSequence |
drop(java.lang.CharSequence self,
int num)
Drops the given number of chars from the head of this CharSequence
if they are available.
|
static java.lang.String |
drop(GString self,
int num)
A GString variant of the equivalent CharSequence method.
|
static java.lang.CharSequence |
dropWhile(java.lang.CharSequence self,
Closure condition)
Create a suffix of the given CharSequence by dropping as many characters as possible from the
front of the original CharSequence such that calling the given closure condition evaluates to
true when passed each of the dropped characters.
|
static java.lang.String |
dropWhile(GString self,
Closure condition)
A GString variant of the equivalent CharSequence method.
|
static <T> T |
eachLine(java.lang.CharSequence self,
Closure<T> closure)
Iterates through this CharSequence line by line.
|
static <T> T |
eachLine(java.lang.CharSequence self,
int firstLine,
Closure<T> closure)
Iterates through this CharSequence line by line.
|
static <T> T |
eachLine(java.lang.String self,
Closure<T> closure)
Deprecated.
Use the CharSequence version
|
static <T> T |
eachLine(java.lang.String self,
int firstLine,
Closure<T> closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
eachMatch(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Process each regex group matched substring of the given pattern.
|
static java.lang.String |
eachMatch(java.lang.String self,
java.lang.String regex,
Closure closure)
Process each regex group matched substring of the given string.
|
static <T extends java.lang.CharSequence> |
eachMatch(T self,
java.lang.CharSequence regex,
Closure closure)
Process each regex group matched substring of the given CharSequence.
|
static <T extends java.lang.CharSequence> |
eachMatch(T self,
java.util.regex.Pattern pattern,
Closure closure)
Process each regex group matched substring of the given pattern.
|
static java.lang.String |
expand(java.lang.CharSequence self)
Expands all tabs into spaces with tabStops of size 8.
|
static java.lang.String |
expand(java.lang.CharSequence self,
int tabStop)
Expands all tabs into spaces.
|
static java.lang.String |
expand(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
expand(java.lang.String self,
int tabStop)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
expandLine(java.lang.CharSequence self,
int tabStop)
Expands all tabs into spaces.
|
static java.lang.String |
expandLine(java.lang.String self,
int tabStop)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
find(java.lang.CharSequence self,
java.lang.CharSequence regex)
Finds the first occurrence of a regular expression String within a String.
|
static java.lang.String |
find(java.lang.CharSequence self,
java.lang.CharSequence regex,
Closure closure)
Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence.
|
static java.lang.String |
find(java.lang.CharSequence self,
java.util.regex.Pattern pattern)
Finds the first occurrence of a compiled regular expression Pattern within a String.
|
static java.lang.String |
find(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
Closure closure)
Returns the result of calling a closure with the first occurrence of a compiled regular expression found within a String.
|
static java.lang.String |
find(java.lang.String self,
java.util.regex.Pattern pattern)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
find(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
find(java.lang.String self,
java.lang.String regex)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
find(java.lang.String self,
java.lang.String regex,
Closure closure)
Deprecated.
Use the CharSequence version
|
static java.util.List<java.lang.String> |
findAll(java.lang.CharSequence self,
java.lang.CharSequence regex)
Returns a (possibly empty) list of all occurrences of a regular expression (provided as a CharSequence) found within a CharSequence.
|
static <T> java.util.List<T> |
findAll(java.lang.CharSequence self,
java.lang.CharSequence regex,
Closure<T> closure)
Finds all occurrences of a regular expression string within a CharSequence.
|
static java.util.List<java.lang.String> |
findAll(java.lang.CharSequence self,
java.util.regex.Pattern pattern)
Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.
|
static <T> java.util.List<T> |
findAll(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Finds all occurrences of a compiled regular expression Pattern within a CharSequence.
|
static java.util.List<java.lang.String> |
findAll(java.lang.String self,
java.util.regex.Pattern pattern)
Deprecated.
Use the CharSequence version
|
static <T> java.util.List<T> |
findAll(java.lang.String self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Deprecated.
Use the CharSequence version
|
static java.util.List<java.lang.String> |
findAll(java.lang.String self,
java.lang.String regex)
Deprecated.
Use the CharSequence version
|
static <T> java.util.List<T> |
findAll(java.lang.String self,
java.lang.String regex,
Closure<T> closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
getAt(java.lang.CharSequence self,
java.util.Collection indices)
Select a List of characters from a CharSequence using a Collection
to identify the indices to be selected.
|
static java.lang.String |
getAt(java.lang.CharSequence text,
EmptyRange range)
Support the range subscript operator for CharSequence or StringBuffer with EmptyRange
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
int index)
Support the subscript operator for CharSequence.
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
IntRange range)
Support the range subscript operator for CharSequence with IntRange
|
static java.lang.CharSequence |
getAt(java.lang.CharSequence text,
Range range)
Support the range subscript operator for CharSequence
|
static java.lang.String |
getAt(GString text,
int index)
Support the subscript operator for GString.
|
static java.lang.String |
getAt(GString text,
IntRange range)
Support the range subscript operator for GString with IntRange
|
static java.lang.String |
getAt(GString text,
Range range)
Support the range subscript operator for GString
|
static java.util.List |
getAt(java.util.regex.Matcher self,
java.util.Collection indices)
Select a List of values from a Matcher using a Collection
to identify the indices to be selected.
|
static java.lang.Object |
getAt(java.util.regex.Matcher matcher,
int idx)
Support the subscript operator, e.g.
|
static java.lang.String |
getAt(java.lang.String self,
java.util.Collection indices)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
getAt(java.lang.String text,
EmptyRange range)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
getAt(java.lang.String text,
int index)
Support the subscript operator for String.
|
static java.lang.String |
getAt(java.lang.String text,
IntRange range)
Support the range subscript operator for String with IntRange
|
static java.lang.String |
getAt(java.lang.String text,
Range range)
Support the range subscript operator for String
|
static char[] |
getChars(java.lang.CharSequence self)
Converts the given CharSequence into an array of characters.
|
static char[] |
getChars(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static int |
getCount(java.util.regex.Matcher matcher)
Find the number of Strings matched to the given Matcher.
|
static boolean |
hasGroup(java.util.regex.Matcher matcher)
Check whether a Matcher contains a group or not.
|
static boolean |
isAllWhitespace(java.lang.CharSequence self)
True if a CharSequence only contains whitespace characters.
|
static boolean |
isAllWhitespace(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isBigDecimal(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as a BigDecimal.
|
static boolean |
isBigDecimal(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isBigInteger(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as a BigInteger.
|
static boolean |
isBigInteger(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isCase(java.lang.CharSequence caseValue,
java.lang.Object switchValue)
'Case' implementation for a CharSequence, which uses equals between the
toString() of the caseValue and the switchValue.
|
static boolean |
isCase(GString caseValue,
java.lang.Object switchValue)
Deprecated.
Use the CharSequence version
|
static boolean |
isCase(java.util.regex.Pattern caseValue,
java.lang.Object switchValue)
'Case' implementation for the
Pattern class, which allows
testing a String against a number of regular expressions. |
static boolean |
isCase(java.lang.String caseValue,
java.lang.Object switchValue)
Deprecated.
Use the CharSequence version
|
static boolean |
isDouble(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as a Double.
|
static boolean |
isDouble(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isFloat(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as a Float.
|
static boolean |
isFloat(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isInteger(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as an Integer.
|
static boolean |
isInteger(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isLong(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as a Long.
|
static boolean |
isLong(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static boolean |
isNumber(java.lang.CharSequence self)
Determine if a CharSequence can be parsed as a Number.
|
static boolean |
isNumber(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.util.Iterator |
iterator(java.util.regex.Matcher matcher)
Returns an
Iterator which traverses each match. |
static java.lang.StringBuilder |
leftShift(java.lang.CharSequence self,
java.lang.Object value)
Overloads the left shift operator to provide an easy way to append multiple
objects as string representations to a CharSequence.
|
static java.lang.StringBuffer |
leftShift(java.lang.StringBuffer self,
java.lang.Object value)
Overloads the left shift operator to provide an easy way to append multiple
objects as string representations to a StringBuffer.
|
static java.lang.StringBuilder |
leftShift(java.lang.StringBuilder self,
java.lang.Object value)
Overloads the left shift operator to provide syntactic sugar for appending to a StringBuilder.
|
static java.lang.StringBuffer |
leftShift(java.lang.String self,
java.lang.Object value)
Overloads the left shift operator to provide an easy way to append multiple
objects as string representations to a String.
|
static boolean |
matches(java.lang.CharSequence self,
java.util.regex.Pattern pattern)
Tells whether or not a CharSequence matches the given
compiled regular expression Pattern.
|
static boolean |
matches(java.lang.String self,
java.util.regex.Pattern pattern)
Deprecated.
Use the CharSequence version
|
static boolean |
matchesPartially(java.util.regex.Matcher matcher)
Given a matcher that matches a string against a pattern,
this method returns true when the string matches the pattern or if a longer string, could match the pattern.
|
static java.lang.String |
minus(java.lang.CharSequence self,
java.lang.Object target)
Remove a part of a CharSequence by replacing the first occurrence
of target within self with '' and returns the result.
|
static java.lang.String |
minus(java.lang.CharSequence self,
java.util.regex.Pattern pattern)
Remove a part of a CharSequence.
|
static java.lang.String |
minus(java.lang.String self,
java.lang.Object target)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
minus(java.lang.String self,
java.util.regex.Pattern pattern)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
multiply(java.lang.CharSequence self,
java.lang.Number factor)
Repeat a CharSequence a certain number of times.
|
static java.lang.String |
multiply(java.lang.String self,
java.lang.Number factor)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
next(java.lang.CharSequence self)
This method is called by the ++ operator for the class CharSequence.
|
static java.lang.String |
next(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
normalize(java.lang.CharSequence self)
Return a String with linefeeds and carriage returns normalized to linefeeds.
|
static java.lang.String |
normalize(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
padLeft(java.lang.CharSequence self,
java.lang.Number numberOfChars)
Pad a CharSequence to a minimum length specified by numberOfChars by adding the space character
to the left as many times as needed.
|
static java.lang.String |
padLeft(java.lang.CharSequence self,
java.lang.Number numberOfChars,
java.lang.CharSequence padding)
Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied
padding CharSequence as many times as needed to the left.
|
static java.lang.String |
padLeft(java.lang.String self,
java.lang.Number numberOfChars)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
padLeft(java.lang.String self,
java.lang.Number numberOfChars,
java.lang.String padding)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
padRight(java.lang.CharSequence self,
java.lang.Number numberOfChars)
Pad a CharSequence to a minimum length specified by numberOfChars by adding the space
character to the right as many times as needed.
|
static java.lang.String |
padRight(java.lang.CharSequence self,
java.lang.Number numberOfChars,
java.lang.CharSequence padding)
Pad a CharSequence to a minimum length specified by numberOfChars, adding the supplied padding
CharSequence as many times as needed to the right.
|
static java.lang.String |
padRight(java.lang.String self,
java.lang.Number numberOfChars)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
padRight(java.lang.String self,
java.lang.Number numberOfChars,
java.lang.String padding)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
plus(java.lang.CharSequence left,
java.lang.Object value)
Appends the String representation of the given operand to this CharSequence.
|
static java.lang.String |
plus(java.lang.Number value,
java.lang.String right)
Appends a String to the string representation of this number.
|
static java.lang.String |
plus(java.lang.StringBuffer left,
java.lang.String value)
Appends a String to this StringBuffer.
|
static java.lang.String |
plus(java.lang.String left,
java.lang.CharSequence value)
Appends the String representation of the given operand to this string.
|
static java.lang.String |
plus(java.lang.String left,
java.lang.Object value)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
previous(java.lang.CharSequence self)
This method is called by the -- operator for the class CharSequence.
|
static java.lang.String |
previous(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static void |
putAt(java.lang.StringBuffer self,
EmptyRange range,
java.lang.Object value)
Support the range subscript operator for StringBuffer.
|
static void |
putAt(java.lang.StringBuffer self,
IntRange range,
java.lang.Object value)
Support the range subscript operator for StringBuffer.
|
static java.util.List<java.lang.String> |
readLines(java.lang.CharSequence self)
Return the lines of a CharSequence as a List of String.
|
static java.util.List<java.lang.String> |
readLines(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
replaceAll(java.lang.CharSequence self,
java.lang.CharSequence regex,
java.lang.CharSequence replacement)
Replaces each substring of this CharSequence that matches the given
regular expression with the given replacement.
|
static java.lang.String |
replaceAll(java.lang.CharSequence self,
java.lang.CharSequence regex,
Closure closure)
Replaces all occurrences of a captured group by the result of calling a closure on that text.
|
static java.lang.String |
replaceAll(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
java.lang.CharSequence replacement)
Replaces all substrings of a CharSequence that match the given
compiled regular expression with the given replacement.
|
static java.lang.String |
replaceAll(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
Closure closure)
Replaces all occurrences of a captured group by the result of a closure call on that text.
|
static java.lang.String |
replaceAll(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
replaceAll(java.lang.String self,
java.util.regex.Pattern pattern,
java.lang.String replacement)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
replaceAll(java.lang.String self,
java.lang.String regex,
Closure closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
replaceFirst(java.lang.CharSequence self,
java.lang.CharSequence regex,
java.lang.CharSequence replacement)
Replaces the first substring of this CharSequence that matches the given
regular expression with the given replacement.
|
static java.lang.String |
replaceFirst(java.lang.CharSequence self,
java.lang.CharSequence regex,
Closure closure)
Replaces the first occurrence of a captured group by the result of a closure call on that text.
|
static java.lang.String |
replaceFirst(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
java.lang.CharSequence replacement)
Replaces the first substring of a CharSequence that matches the given
compiled regular expression with the given replacement.
|
static java.lang.String |
replaceFirst(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
Closure closure)
Replaces the first occurrence of a captured group by the result of a closure call on that text.
|
static java.lang.String |
replaceFirst(java.lang.String self,
java.util.regex.Pattern pattern,
Closure closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
replaceFirst(java.lang.String self,
java.util.regex.Pattern pattern,
java.lang.String replacement)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
replaceFirst(java.lang.String self,
java.lang.String regex,
Closure closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
reverse(java.lang.CharSequence self)
Creates a String which is the reverse (backwards) of this CharSequence
|
static java.lang.String |
reverse(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static void |
setIndex(java.util.regex.Matcher matcher,
int idx)
Set the position of the given Matcher to the given index.
|
static int |
size(java.lang.CharSequence text)
Provide the standard Groovy
size() method for CharSequence . |
static long |
size(java.util.regex.Matcher self)
Provide the standard Groovy
size() method for Matcher . |
static int |
size(java.lang.String text)
Provide the standard Groovy
size() method for String . |
static int |
size(java.lang.StringBuffer buffer)
Provide the standard Groovy
size() method for StringBuffer . |
static java.lang.String[] |
split(java.lang.CharSequence self)
Convenience method to split a CharSequence (with whitespace as delimiter).
|
static java.lang.String[] |
split(GString self)
Deprecated.
Use the CharSequence version
|
static java.lang.String[] |
split(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static <T> T |
splitEachLine(java.lang.CharSequence self,
java.lang.CharSequence regex,
Closure<T> closure)
Iterates through the given CharSequence line by line, splitting each line using
the given regex delimiter.
|
static <T> T |
splitEachLine(java.lang.CharSequence self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Iterates through the given CharSequence line by line, splitting each line using
the given separator Pattern.
|
static <T> T |
splitEachLine(java.lang.String self,
java.util.regex.Pattern pattern,
Closure<T> closure)
Deprecated.
Use the CharSequence version
|
static <T> T |
splitEachLine(java.lang.String self,
java.lang.String regex,
Closure<T> closure)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
stripIndent(java.lang.CharSequence self)
Strip leading spaces from every line in a CharSequence.
|
static java.lang.String |
stripIndent(java.lang.CharSequence self,
int numChars)
Strip numChar leading characters from
every line in a CharSequence.
|
static java.lang.String |
stripIndent(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
stripIndent(java.lang.String self,
int numChars)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
stripMargin(java.lang.CharSequence self)
Strip leading whitespace/control characters followed by '|' from
every line in a CharSequence.
|
static java.lang.String |
stripMargin(java.lang.CharSequence self,
char marginChar)
Strip leading whitespace/control characters followed by marginChar from
every line in a CharSequence.
|
static java.lang.String |
stripMargin(java.lang.CharSequence self,
java.lang.CharSequence marginChar)
Strip leading whitespace/control characters followed by marginChar from
every line in a CharSequence.
|
static java.lang.String |
stripMargin(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
stripMargin(java.lang.String self,
char marginChar)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
stripMargin(java.lang.String self,
java.lang.String marginChar)
Deprecated.
Use the CharSequence version
|
static java.lang.CharSequence |
take(java.lang.CharSequence self,
int num)
Returns the first
num elements from this CharSequence. |
static java.lang.String |
take(GString self,
int num)
A GString variant of the equivalent CharSequence method.
|
static java.lang.CharSequence |
takeWhile(java.lang.CharSequence self,
Closure condition)
Returns the longest prefix of this CharSequence where each
element passed to the given closure evaluates to true.
|
static java.lang.String |
takeWhile(GString self,
Closure condition)
A GString variant of the equivalent GString method.
|
static java.math.BigDecimal |
toBigDecimal(java.lang.CharSequence self)
Parse a CharSequence into a BigDecimal
|
static java.math.BigDecimal |
toBigDecimal(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.math.BigInteger |
toBigInteger(java.lang.CharSequence self)
Parse a CharSequence into a BigInteger
|
static java.math.BigInteger |
toBigInteger(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.Boolean |
toBoolean(java.lang.String self)
Converts the given string into a Boolean object.
|
static java.lang.Character |
toCharacter(java.lang.String self)
Converts the given string into a Character object
using the first character in the string.
|
static java.lang.Double |
toDouble(java.lang.CharSequence self)
Parse a CharSequence into a Double
|
static java.lang.Double |
toDouble(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.Float |
toFloat(java.lang.CharSequence self)
Parse a CharSequence into a Float
|
static java.lang.Float |
toFloat(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.Integer |
toInteger(java.lang.CharSequence self)
Parse a CharSequence into an Integer
|
static java.lang.Integer |
toInteger(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.util.List<java.lang.String> |
tokenize(java.lang.CharSequence self)
Tokenize a CharSequence (with a whitespace as the delimiter).
|
static java.util.List<java.lang.String> |
tokenize(java.lang.CharSequence self,
java.lang.Character delimiter)
Tokenize a CharSequence based on the given character delimiter.
|
static java.util.List<java.lang.String> |
tokenize(java.lang.CharSequence self,
java.lang.CharSequence delimiters)
Tokenize a CharSequence based on the given CharSequence.
|
static java.util.List<java.lang.String> |
tokenize(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.util.List<java.lang.String> |
tokenize(java.lang.String self,
java.lang.Character delimiter)
Deprecated.
Use the CharSequence version
|
static java.util.List<java.lang.String> |
tokenize(java.lang.String self,
java.lang.String delimiters)
Deprecated.
Use the CharSequence version
|
static java.util.List<java.lang.String> |
toList(java.lang.CharSequence self)
Converts the given CharSequence into a List of Strings of one character.
|
static java.util.List<java.lang.String> |
toList(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.Long |
toLong(java.lang.CharSequence self)
Parse a CharSequence into a Long
|
static java.lang.Long |
toLong(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.util.Set<java.lang.String> |
toSet(java.lang.CharSequence self)
Converts the given CharSequence into a Set of unique Strings of one character.
|
static java.util.Set<java.lang.String> |
toSet(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.Short |
toShort(java.lang.CharSequence self)
Parse a CharSequence into a Short
|
static java.lang.Short |
toShort(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
tr(java.lang.CharSequence self,
java.lang.CharSequence sourceSet,
java.lang.CharSequence replacementSet)
Translates a CharSequence by replacing characters from the sourceSet with characters from replacementSet.
|
static java.lang.String |
tr(java.lang.String self,
java.lang.String sourceSet,
java.lang.String replacementSet)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
uncapitalize(java.lang.CharSequence self)
Convenience method to uncapitalize the first letter of a CharSequence
(typically the first letter of a word).
|
static java.lang.String |
unexpand(java.lang.CharSequence self)
Replaces sequences of whitespaces with tabs using tabStops of size 8.
|
static java.lang.String |
unexpand(java.lang.CharSequence self,
int tabStop)
Replaces sequences of whitespaces with tabs.
|
static java.lang.String |
unexpand(java.lang.String self)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
unexpand(java.lang.String self,
int tabStop)
Deprecated.
Use the CharSequence version
|
static java.lang.String |
unexpandLine(java.lang.CharSequence self,
int tabStop)
Replaces sequences of whitespaces with tabs within a line.
|
static java.lang.String |
unexpandLine(java.lang.String self,
int tabStop)
Deprecated.
Use the CharSequence version
|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders
public static boolean asBoolean(java.lang.CharSequence string)
string
- the character sequencepublic static boolean asBoolean(java.util.regex.Matcher matcher)
matcher
- the matcherpublic static <T> T asType(java.lang.CharSequence self, java.lang.Class<T> c)
Provides a method to perform custom 'dynamic' type conversion
to the given class using the as
operator.
self
- a CharSequencec
- the desired classasType(String, Class)
public static <T> T asType(GString self, java.lang.Class<T> c)
DefaultGroovyMethods.asType(Object, Class)
self
- a GStringc
- the desired classpublic static <T> T asType(java.lang.String self, java.lang.Class<T> c)
as
operator.
Example: '123' as Double
By default, the following types are supported:
DefaultGroovyMethods.asType(Object, Class)
.self
- a Stringc
- the desired classpublic static java.util.regex.Pattern bitwiseNegate(java.lang.CharSequence self)
self
- a String to convert into a regular expression@Deprecated public static java.util.regex.Pattern bitwiseNegate(java.lang.String self)
bitwiseNegate(CharSequence)
public static java.lang.String uncapitalize(java.lang.CharSequence self)
assert 'H'.uncapitalize() == 'h' assert 'Hello'.uncapitalize() == 'hello' assert 'Hello world'.uncapitalize() == 'hello world' assert 'Hello World'.uncapitalize() == 'hello World' assert 'hello world' == 'Hello World'.split(' ').collect{ it.uncapitalize() }.join(' ')
self
- The CharSequence to uncapitalizepublic static java.lang.String capitalize(java.lang.CharSequence self)
assert 'h'.capitalize() == 'H' assert 'hello'.capitalize() == 'Hello' assert 'hello world'.capitalize() == 'Hello world' assert 'Hello World' == 'hello world'.split(' ').collect{ it.capitalize() }.join(' ')
self
- The CharSequence to capitalizecapitalize(String)
@Deprecated public static java.lang.String capitalize(java.lang.String self)
capitalize(CharSequence)
public static java.lang.String center(java.lang.CharSequence self, java.lang.Number numberOfChars)
['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6) + '|' }will produce output like:
| A | | BB | | CCC | | DDDD |
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resultcenter(String, Number)
public static java.lang.String center(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6, '+') + '|' }will produce output like:
|++A+++| |++BB++| |+CCC++| |+DDDD+|
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for paddingcenter(String, Number, String)
@Deprecated public static java.lang.String center(java.lang.String self, java.lang.Number numberOfChars)
center(CharSequence, Number)
@Deprecated public static java.lang.String center(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
public static boolean contains(java.lang.CharSequence self, java.lang.CharSequence text)
Collection.contains(Object)
to make CharSequences more polymorphic.self
- a CharSequencetext
- the CharSequence to look forcontains(String, String)
@Deprecated public static boolean contains(java.lang.String self, java.lang.String text)
contains(CharSequence, CharSequence)
public static int count(java.lang.CharSequence self, java.lang.CharSequence text)
self
- a CharSequencetext
- a sub CharSequencecount(String, String)
@Deprecated public static int count(java.lang.String self, java.lang.String text)
contains(CharSequence, CharSequence)
public static java.lang.String denormalize(java.lang.CharSequence self)
self
- a CharSequence objectdenormalize(String)
@Deprecated public static java.lang.String denormalize(java.lang.String self)
denormalize(CharSequence)
public static java.lang.CharSequence drop(java.lang.CharSequence self, int num)
def text = "Groovy" assert text.drop( 0 ) == 'Groovy' assert text.drop( 2 ) == 'oovy' assert text.drop( 7 ) == ''
self
- the original CharSequencenum
- the number of characters to drop from this iteratornum
ones,
or else an empty String, if this CharSequence has less than num
characters.public static java.lang.String drop(GString self, int num)
self
- the original GStringnum
- the number of characters to drop from this iteratornum
ones,
or else an empty String, if the toString() of this GString has less than num
characters.drop(CharSequence, int)
public static java.lang.CharSequence dropWhile(java.lang.CharSequence self, Closure condition)
def text = "Groovy" assert text.dropWhile{ false } == 'Groovy' assert text.dropWhile{ true } == '' assert text.dropWhile{ it < 'Z' } == 'roovy' assert text.dropWhile{ it != 'v' } == 'vy'
self
- the original CharSequencecondition
- the closure that while continuously evaluating to true will cause us to drop elements from
the front of the original CharSequencepublic static java.lang.String dropWhile(GString self, Closure condition)
self
- the original GStringcondition
- the closure that while continuously evaluating to true will cause us to drop elements from
the front of the original GStringdropWhile(CharSequence, groovy.lang.Closure)
public static <T> T eachLine(java.lang.CharSequence self, Closure<T> closure) throws java.io.IOException
self
- a CharSequenceclosure
- a closurejava.io.IOException
- if an error occurseachLine(String, groovy.lang.Closure)
public static <T> T eachLine(java.lang.CharSequence self, int firstLine, Closure<T> closure) throws java.io.IOException
self
- a CharSequencefirstLine
- the line number value used for the first line (default is 1, set to 0 to start counting from 0)closure
- a closure (arg 1 is line, optional arg 2 is line number)java.io.IOException
- if an error occurs@Deprecated public static <T> T eachLine(java.lang.String self, Closure<T> closure) throws java.io.IOException
java.io.IOException
eachLine(CharSequence, groovy.lang.Closure)
@Deprecated public static <T> T eachLine(java.lang.String self, int firstLine, Closure<T> closure) throws java.io.IOException
java.io.IOException
eachLine(CharSequence, int, groovy.lang.Closure)
public static java.lang.String collectReplacements(java.lang.String orig, Closure<java.lang.String> transform)
transform
Closure should return null
to indicate that no transformation is
required for the given character.
assert "Groovy".collectReplacements{ it == 'o' ? '_O_' : null } == 'Gr_O__O_vy' assert "B&W".collectReplacements{ it == '&' ? '&' : null } == 'B&W'
orig
- the original Stringtransform
Closure.public static <T extends java.lang.CharSequence> T eachMatch(T self, java.lang.CharSequence regex, Closure closure)
self
- the source CharSequenceregex
- a Regex CharSequenceclosure
- a closure with one parameter or as much parameters as groupseachMatch(String, String, groovy.lang.Closure)
public static <T extends java.lang.CharSequence> T eachMatch(T self, java.util.regex.Pattern pattern, Closure closure)
self
- the source CharSequencepattern
- a regex Patternclosure
- a closure with one parameter or as much parameters as groupseachMatch(String, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.String eachMatch(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
self
- the source stringpattern
- a regex Patternclosure
- a closure with one parameter or as much parameters as groupspublic static java.lang.String eachMatch(java.lang.String self, java.lang.String regex, Closure closure)
self
- the source stringregex
- a Regex stringclosure
- a closure with one parameter or as much parameters as groupspublic static java.lang.String expand(java.lang.CharSequence self)
self
- A CharSequence to expandexpand(String)
public static java.lang.String expand(java.lang.CharSequence self, int tabStop)
self
- A CharSequence to expandtabStop
- The number of spaces a tab representsexpand(String, int)
@Deprecated public static java.lang.String expand(java.lang.String self)
expand(CharSequence)
@Deprecated public static java.lang.String expand(java.lang.String self, int tabStop)
expand(CharSequence, int)
public static java.lang.String expandLine(java.lang.CharSequence self, int tabStop)
self
- A line to expandtabStop
- The number of spaces a tab representsexpandLine(String, int)
@Deprecated public static java.lang.String expandLine(java.lang.String self, int tabStop)
expand(CharSequence, int)
public static java.lang.String find(java.lang.CharSequence self, java.lang.CharSequence regex)
For example, if the regex doesn't match the result is null:
assert "New York, NY".find(/\d{5}/) == nullIf it does match, we get the matching string back:
assert "New York, NY 10292-0098".find(/\d{5}/) == "10292"If we have capture groups in our expression, we still get back the full match
assert "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/) == "10292-0098"
self
- a CharSequenceregex
- the capturing regexfind(String, java.util.regex.Pattern)
public static java.lang.String find(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
self
- a CharSequenceregex
- the capturing regex CharSequenceclosure
- the closure that will be passed the full match, plus each of the capturing groups (if any)find(String, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.String find(java.lang.CharSequence self, java.util.regex.Pattern pattern)
For example, if the pattern doesn't match the result is null:
assert "New York, NY".find(~/\d{5}/) == nullIf it does match, we get the matching string back:
assert "New York, NY 10292-0098".find(~/\d{5}/) == "10292"If we have capture groups in our expression, the groups are ignored and we get back the full match:
assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) == "10292-0098"If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.
self
- a CharSequencepattern
- the compiled regex Patternfind(String, java.util.regex.Pattern)
public static java.lang.String find(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
For example, if the pattern doesn't match, the result is null:
assert "New York, NY".find(~/\d{5}/) { match -> return "-$match-"} == nullIf it does match and we don't have any capture groups in our regex, there is a single parameter on the closure that the match gets passed to:
assert "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"} == "-10292-"If we have capture groups in our expression, our closure has one parameter for the match, followed by one for each of the capture groups:
assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour -> assert match == "10292-0098" assert zip == "10292" assert plusFour == "0098" return zip } == "10292"If we have capture groups in our expression, and our closure has one parameter, the closure will be passed an array with the first element corresponding to the whole match, followed by an element for each of the capture groups:
assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { array -> assert array[0] == "10292-0098" assert array[1] == "10292" assert array[2] == "0098" return array[1] } == "10292"If a capture group is optional, and doesn't match, then the corresponding value for that capture group passed to the closure will be null as illustrated here:
assert "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber -> assert "233-9999" == match assert null == areaCode assert "233" == exchange assert "9999" == stationNumber return "$exchange$stationNumber" } == "2339999"
self
- a CharSequencepattern
- the compiled regex Patternclosure
- the closure that will be passed the full match, plus each of the capturing groups (if any)find(String, java.util.regex.Pattern, groovy.lang.Closure)
@Deprecated public static java.lang.String find(java.lang.String self, java.util.regex.Pattern pattern)
@Deprecated public static java.lang.String find(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
@Deprecated public static java.lang.String find(java.lang.String self, java.lang.String regex)
find(CharSequence, CharSequence)
@Deprecated public static java.lang.String find(java.lang.String self, java.lang.String regex, Closure closure)
public static java.util.List<java.lang.String> findAll(java.lang.CharSequence self, java.lang.CharSequence regex)
For example, if the regex doesn't match, it returns an empty list:
assert "foo".findAll(/(\w*) Fish/) == []Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"] assert "One Fish, Two Fish, Red Fish, Blue Fish".findAll(/(\w*) Fish/) == expectedIf you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or use eachMatch.
self
- a CharSequenceregex
- the capturing regex CharSequencefindAll(CharSequence, Pattern)
public static <T> java.util.List<T> findAll(java.lang.CharSequence self, java.lang.CharSequence regex, Closure<T> closure)
If there are no matches, the closure will not be called, and an empty List will be returned.
For example, if the regex doesn't match, it returns an empty list:
assert "foo".findAll(/(\w*) Fish/) { match, firstWord -> return firstWord } == []Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:
assert "I could not, would not, with a fox.".findAll(/.ould/) { match -> "${match}n't"} == ["couldn't", "wouldn't"]If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
def orig = "There's a Wocket in my Pocket" assert orig.findAll(/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" } == ["W > Wocket", "P > Pocket"]
self
- a CharSequenceregex
- the capturing regex CharSequenceclosure
- will be passed the full match plus each of the capturing groups (if any)findAll(CharSequence, Pattern, groovy.lang.Closure)
public static java.util.List<java.lang.String> findAll(java.lang.CharSequence self, java.util.regex.Pattern pattern)
For example, if the pattern doesn't match, it returns an empty list:
assert "foo".findAll(~/(\w*) Fish/) == []Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"] assert "One Fish, Two Fish, Red Fish, Blue Fish".findAll(~/(\w*) Fish/) == expected
self
- a CharSequencepattern
- the compiled regex PatternfindAll(String, java.util.regex.Pattern)
public static <T> java.util.List<T> findAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure<T> closure)
If there are no matches, the closure will not be called, and an empty List will be returned.
For example, if the pattern doesn't match, it returns an empty list:
assert "foo".findAll(~/(\w*) Fish/) { match, firstWord -> return firstWord } == []Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:
assert "I could not, would not, with a fox.".findAll(~/.ould/) { match -> "${match}n't"} == ["couldn't", "wouldn't"]If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
def orig = "There's a Wocket in my Pocket" assert orig.findAll(~/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" } == ["W > Wocket", "P > Pocket"]
self
- a CharSequencepattern
- the compiled regex Patternclosure
- will be passed the full match plus each of the capturing groups (if any)findAll(String, java.util.regex.Pattern, groovy.lang.Closure)
@Deprecated public static java.util.List<java.lang.String> findAll(java.lang.String self, java.util.regex.Pattern pattern)
@Deprecated public static <T> java.util.List<T> findAll(java.lang.String self, java.util.regex.Pattern pattern, Closure<T> closure)
@Deprecated public static java.util.List<java.lang.String> findAll(java.lang.String self, java.lang.String regex)
findAll(CharSequence, CharSequence)
@Deprecated public static <T> java.util.List<T> findAll(java.lang.String self, java.lang.String regex, Closure<T> closure)
public static java.lang.String getAt(java.lang.CharSequence self, java.util.Collection indices)
self
- a CharSequenceindices
- a Collection of indicespublic static java.lang.String getAt(java.lang.CharSequence text, EmptyRange range)
text
- a CharSequencerange
- an EmptyRangepublic static java.lang.CharSequence getAt(java.lang.CharSequence text, int index)
text
- a CharSequenceindex
- the index of the Character to getpublic static java.lang.String getAt(GString text, int index)
text
- a GStringindex
- the index of the Character to getpublic static java.lang.CharSequence getAt(java.lang.CharSequence text, IntRange range)
text
- a CharSequencerange
- an IntRangepublic static java.lang.String getAt(GString text, IntRange range)
text
- a GStringrange
- an IntRangepublic static java.lang.CharSequence getAt(java.lang.CharSequence text, Range range)
text
- a CharSequencerange
- a Rangepublic static java.lang.String getAt(GString text, Range range)
text
- a GStringrange
- a Rangepublic static java.util.List getAt(java.util.regex.Matcher self, java.util.Collection indices)
self
- a Matcherindices
- a Collection of indicespublic static java.lang.Object getAt(java.util.regex.Matcher matcher, int idx)
For an example using no group match,
def p = /ab[d|f]/ def m = "abcabdabeabf" =~ p assert 2 == m.count assert 2 == m.size() // synonym for m.getCount() assert ! m.hasGroup() assert 0 == m.groupCount() def matches = ["abd", "abf"] for (i in 0..<m.count) { assert m[i] == matches[i] }
For an example using group matches,
def p = /(?:ab([c|d|e|f]))/ def m = "abcabdabeabf" =~ p assert 4 == m.count assert m.hasGroup() assert 1 == m.groupCount() def matches = [["abc", "c"], ["abd", "d"], ["abe", "e"], ["abf", "f"]] for (i in 0..<m.count) { assert m[i] == matches[i] }
For another example using group matches,
def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/ assert 3 == m.count assert m.hasGroup() assert 1 == m.groupCount() def matches = [["abd", "d"], ["abxyz", "xyz"], ["abx", "x"]] for (i in 0..<m.count) { assert m[i] == matches[i] }
matcher
- a Matcheridx
- an indexpublic static boolean matchesPartially(java.util.regex.Matcher matcher)
def emailPattern = /\w+@\w+\.\w{2,}/ def matcher = "john@doe" =~ emailPattern assert matcher.matchesPartially() matcher = "john@doe.com" =~ emailPattern assert matcher.matchesPartially() matcher = "john@@" =~ emailPattern assert !matcher.matchesPartially()
matcher
- the Matcher@Deprecated public static java.lang.String getAt(java.lang.String self, java.util.Collection indices)
@Deprecated public static java.lang.String getAt(java.lang.String text, EmptyRange range)
public static java.lang.String getAt(java.lang.String text, int index)
text
- a Stringindex
- the index of the Character to getpublic static java.lang.String getAt(java.lang.String text, IntRange range)
text
- a Stringrange
- an IntRangepublic static java.lang.String getAt(java.lang.String text, Range range)
text
- a Stringrange
- a Rangepublic static char[] getChars(java.lang.CharSequence self)
self
- a CharSequencegetChars(String)
@Deprecated public static char[] getChars(java.lang.String self)
getChars(CharSequence)
public static int getCount(java.util.regex.Matcher matcher)
matcher
- a Matcherpublic static boolean hasGroup(java.util.regex.Matcher matcher)
matcher
- a Matchertrue
if matcher contains at least one group.public static boolean isAllWhitespace(java.lang.CharSequence self)
self
- The CharSequence to check the characters inisAllWhitespace(String)
@Deprecated public static boolean isAllWhitespace(java.lang.String self)
isAllWhitespace(CharSequence)
public static boolean isBigDecimal(java.lang.CharSequence self)
self
- a CharSequenceisBigDecimal(String)
@Deprecated public static boolean isBigDecimal(java.lang.String self)
isBigDecimal(CharSequence)
public static boolean isBigInteger(java.lang.CharSequence self)
self
- a CharSequenceisBigInteger(String)
@Deprecated public static boolean isBigInteger(java.lang.String self)
isBigInteger(CharSequence)
public static boolean isCase(java.lang.CharSequence caseValue, java.lang.Object switchValue)
switch( str ) { case 'one' : // etc... }Note that this returns
true
for the case where both the
'switch' and 'case' operand is null
.caseValue
- the case valueswitchValue
- the switch value@Deprecated public static boolean isCase(GString caseValue, java.lang.Object switchValue)
isCase(CharSequence, Object)
public static boolean isCase(java.util.regex.Pattern caseValue, java.lang.Object switchValue)
Pattern
class, which allows
testing a String against a number of regular expressions.
For example:
switch( str ) { case ~/one/ : // the regex 'one' matches the value of str }Note that this returns true for the case where both the pattern and the 'switch' values are
null
.caseValue
- the case valueswitchValue
- the switch value@Deprecated public static boolean isCase(java.lang.String caseValue, java.lang.Object switchValue)
isCase(CharSequence, Object)
public static boolean isDouble(java.lang.CharSequence self)
self
- a CharSequenceisDouble(String)
@Deprecated public static boolean isDouble(java.lang.String self)
isDouble(CharSequence)
public static boolean isFloat(java.lang.CharSequence self)
self
- a CharSequenceisFloat(String)
@Deprecated public static boolean isFloat(java.lang.String self)
isFloat(CharSequence)
public static boolean isInteger(java.lang.CharSequence self)
self
- a CharSequenceisInteger(String)
@Deprecated public static boolean isInteger(java.lang.String self)
isInteger(CharSequence)
public static boolean isLong(java.lang.CharSequence self)
self
- a CharSequenceisLong(String)
@Deprecated public static boolean isLong(java.lang.String self)
isLong(CharSequence)
public static boolean isNumber(java.lang.CharSequence self)
self
- a CharSequenceisBigDecimal(CharSequence)
@Deprecated public static boolean isNumber(java.lang.String self)
isNumber(CharSequence)
public static java.util.Iterator iterator(java.util.regex.Matcher matcher)
Iterator
which traverses each match.matcher
- a Matcher objectMatcher.group()
public static java.lang.StringBuilder leftShift(java.lang.CharSequence self, java.lang.Object value)
self
- a CharSequencevalue
- an Objectpublic static java.lang.StringBuffer leftShift(java.lang.String self, java.lang.Object value)
self
- a Stringvalue
- an Objectpublic static java.lang.StringBuffer leftShift(java.lang.StringBuffer self, java.lang.Object value)
self
- a StringBuffervalue
- a value to appendpublic static java.lang.StringBuilder leftShift(java.lang.StringBuilder self, java.lang.Object value)
self
- a StringBuildervalue
- an Objectpublic static boolean matches(java.lang.CharSequence self, java.util.regex.Pattern pattern)
self
- the CharSequence that is to be matchedpattern
- the regex Pattern to which the string of interest is to be matchedString.matches(String)
@Deprecated public static boolean matches(java.lang.String self, java.util.regex.Pattern pattern)
matches(CharSequence, Pattern)
public static java.lang.String minus(java.lang.CharSequence self, java.lang.Object target)
self
- a CharSequencetarget
- an object representing the part to removeminus(String, Object)
public static java.lang.String minus(java.lang.CharSequence self, java.util.regex.Pattern pattern)
self
- a Stringpattern
- a Pattern representing the part to remove@Deprecated public static java.lang.String minus(java.lang.String self, java.util.regex.Pattern pattern)
@Deprecated public static java.lang.String minus(java.lang.String self, java.lang.Object target)
minus(CharSequence, Object)
public static java.lang.String multiply(java.lang.CharSequence self, java.lang.Number factor)
self
- a CharSequence to be repeatedfactor
- the number of times the CharSequence should be repeatedjava.lang.IllegalArgumentException
- if the number of repetitions is < 0@Deprecated public static java.lang.String multiply(java.lang.String self, java.lang.Number factor)
multiply(CharSequence, Number)
public static java.lang.String next(java.lang.CharSequence self)
self
- a CharSequence@Deprecated public static java.lang.String next(java.lang.String self)
next(CharSequence)
public static java.lang.String normalize(java.lang.CharSequence self)
self
- a CharSequence objectnormalize(String)
@Deprecated public static java.lang.String normalize(java.lang.String self)
normalize(CharSequence)
public static java.lang.String padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars)
println 'Numbers:' [1, 10, 100, 1000].each{ println it.toString().padLeft(5) }will produce output like:
Numbers: 1 10 100 1000
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadLeft(CharSequence, Number, CharSequence)
public static java.lang.String padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
println 'Numbers:' [1, 10, 100, 1000].each{ println it.toString().padLeft(5, '*') } [2, 20, 200, 2000].each{ println it.toString().padLeft(5, '*_') }will produce output like:
Numbers: ****1 ***10 **100 *1000 *_*_2 *_*20 *_200 *2000
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for paddingpadLeft(String, Number, String)
@Deprecated public static java.lang.String padLeft(java.lang.String self, java.lang.Number numberOfChars)
padLeft(CharSequence, Number)
@Deprecated public static java.lang.String padLeft(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
public static java.lang.String padRight(java.lang.CharSequence self, java.lang.Number numberOfChars)
['A', 'BB', 'CCC', 'DDDD'].each{ println it.padRight(5) + it.size() }will produce output like:
A 1 BB 2 CCC 3 DDDD 4
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting stringpadRight(String, Number)
public static java.lang.String padRight(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)
['A', 'BB', 'CCC', 'DDDD'].each{ println it.padRight(5, '#') + it.size() }will produce output like:
A####1 BB###2 CCC##3 DDDD#4
self
- a CharSequence objectnumberOfChars
- the total minimum number of characters of the resulting CharSequencepadding
- the characters used for padding@Deprecated public static java.lang.String padRight(java.lang.String self, java.lang.Number numberOfChars)
padRight(CharSequence, Number)
@Deprecated public static java.lang.String padRight(java.lang.String self, java.lang.Number numberOfChars, java.lang.String padding)
public static java.lang.String plus(java.lang.CharSequence left, java.lang.Object value)
left
- a CharSequencevalue
- any Objectpublic static java.lang.String plus(java.lang.Number value, java.lang.String right)
value
- a Numberright
- a String@Deprecated public static java.lang.String plus(java.lang.String left, java.lang.Object value)
plus(CharSequence, Object)
public static java.lang.String plus(java.lang.String left, java.lang.CharSequence value)
left
- a Stringvalue
- any CharSequencepublic static java.lang.String plus(java.lang.StringBuffer left, java.lang.String value)
left
- a StringBuffervalue
- a Stringpublic static java.lang.String previous(java.lang.CharSequence self)
self
- a CharSequenceprevious(String)
@Deprecated public static java.lang.String previous(java.lang.String self)
previous(CharSequence)
public static void putAt(java.lang.StringBuffer self, EmptyRange range, java.lang.Object value)
self
- a StringBufferrange
- a Rangevalue
- the object that's toString() will be insertedpublic static void putAt(java.lang.StringBuffer self, IntRange range, java.lang.Object value)
self
- a StringBufferrange
- a Rangevalue
- the object that's toString() will be insertedpublic static java.util.List<java.lang.String> readLines(java.lang.CharSequence self)
self
- a CharSequence object@Deprecated public static java.util.List<java.lang.String> readLines(java.lang.String self)
readLines(CharSequence)
public static java.lang.String replaceAll(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
self
- a CharSequenceregex
- the capturing regexreplacement
- the string to be substituted for each matchjava.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.replaceAll(String, String)
public static java.lang.String replaceAll(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
Examples:
assert "hello world".replaceAll("(o)") { it[0].toUpperCase() } == "hellO wOrld" assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) == "FOOBAR-FOOBAR-" // Here, // it[0] is the global string of the matched group // it[1] is the first string in the matched group // it[2] is the second string in the matched group assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) == "FOO-FOO-" // Here, // x is the global string of the matched group // y is the first string in the matched group // z is the second string in the matched groupNote that unlike String.replaceAll(String regex, String replacement), where the replacement string treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string and that value is used literally for the replacement.
self
- a CharSequenceregex
- the capturing regexclosure
- the closure to apply on each captured groupjava.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidreplaceAll(String, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.String replaceAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
Note that backslashes (\) and dollar signs ($) in the
replacement string may cause the results to be different than if it were
being treated as a literal replacement string; see
Matcher.replaceAll(java.lang.String)
.
Use Matcher.quoteReplacement(java.lang.String)
to suppress the special
meaning of these characters, if desired.
assert "foo".replaceAll('o', 'X') == 'fXX'
self
- the CharSequence that is to be matchedpattern
- the regex Pattern to which the CharSequence of interest is to be matchedreplacement
- the CharSequence to be substituted for the first matchreplaceAll(String, java.util.regex.Pattern, String)
public static java.lang.String replaceAll(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
For examples,
assert "hello world".replaceAll(~"(o)") { it[0].toUpperCase() } == "hellO wOrld" assert "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { it[0].toUpperCase() }) == "FOOBAR-FOOBAR-" // Here, // it[0] is the global string of the matched group // it[1] is the first string in the matched group // it[2] is the second string in the matched group assert "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) == "FOOBAR-FOOBAR-" // Here, // it[0] is the global string of the matched group // it[1] is the first string in the matched group // it[2] is the second string in the matched group assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) == "FOO-FOO-" // Here, // x is the global string of the matched group // y is the first string in the matched group // z is the second string in the matched groupNote that unlike String.replaceAll(String regex, String replacement), where the replacement string treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string and that value is used literally for the replacement.
self
- a CharSequencepattern
- the capturing regex Patternclosure
- the closure to apply on each captured groupMatcher.quoteReplacement(String)
@Deprecated public static java.lang.String replaceAll(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
@Deprecated public static java.lang.String replaceAll(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
@Deprecated public static java.lang.String replaceAll(java.lang.String self, java.lang.String regex, Closure closure)
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.lang.CharSequence regex, java.lang.CharSequence replacement)
self
- a CharSequenceregex
- the capturing regexreplacement
- the CharSequence to be substituted for each matchjava.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidString.replaceFirst(String, String)
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.lang.CharSequence regex, Closure closure)
For example (with some replaceAll variants thrown in for comparison purposes),
assert "hello world".replaceFirst("(o)") { it[0].toUpperCase() } == "hellO world" // first match assert "hello world".replaceAll("(o)") { it[0].toUpperCase() } == "hellO wOrld" // all matches assert "one fish, two fish".replaceFirst(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } == '1-FISH, two fish' assert "one fish, two fish".replaceAll(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } == '1-FISH, 2-FISH'
self
- a CharSequenceregex
- the capturing regexclosure
- the closure to apply on the first captured groupjava.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidreplaceFirst(String, String, groovy.lang.Closure)
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.util.regex.Pattern pattern, java.lang.CharSequence replacement)
Note that backslashes (\) and dollar signs ($) in the
replacement string may cause the results to be different than if it were
being treated as a literal replacement string; see
Matcher.replaceFirst(java.lang.String)
.
Use Matcher.quoteReplacement(java.lang.String)
to suppress the special
meaning of these characters, if desired.
assert "foo".replaceFirst('o', 'X') == 'fXo'
self
- the CharSequence that is to be matchedpattern
- the regex Pattern to which the CharSequence of interest is to be matchedreplacement
- the CharSequence to be substituted for the first matchreplaceFirst(String, java.util.regex.Pattern, String)
public static java.lang.String replaceFirst(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure closure)
For example (with some replaceAll variants thrown in for comparison purposes),
assert "hellO world" == "hello world".replaceFirst(~"(o)") { it[0].toUpperCase() } // first match assert "hellO wOrld" == "hello world".replaceAll(~"(o)") { it[0].toUpperCase() } // all matches assert '1-FISH, two fish' == "one fish, two fish".replaceFirst(~/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } assert '1-FISH, 2-FISH' == "one fish, two fish".replaceAll(~/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() }
self
- a CharSequencepattern
- the capturing regex Patternclosure
- the closure to apply on the first captured group@Deprecated public static java.lang.String replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)
@Deprecated public static java.lang.String replaceFirst(java.lang.String self, java.util.regex.Pattern pattern, java.lang.String replacement)
@Deprecated public static java.lang.String replaceFirst(java.lang.String self, java.lang.String regex, Closure closure)
public static java.lang.String reverse(java.lang.CharSequence self)
self
- a CharSequencereverse(String)
@Deprecated public static java.lang.String reverse(java.lang.String self)
reverse(CharSequence)
public static void setIndex(java.util.regex.Matcher matcher, int idx)
matcher
- a Matcheridx
- the index numberpublic static int size(java.lang.CharSequence text)
size()
method for CharSequence
.text
- a CharSequencepublic static long size(java.util.regex.Matcher self)
size()
method for Matcher
.self
- a matcher objectpublic static int size(java.lang.String text)
size()
method for String
.text
- a Stringpublic static int size(java.lang.StringBuffer buffer)
size()
method for StringBuffer
.buffer
- a StringBufferpublic static java.lang.String[] split(java.lang.CharSequence self)
self
- the CharSequence to splitsplit(String)
@Deprecated public static java.lang.String[] split(GString self)
split(CharSequence)
@Deprecated public static java.lang.String[] split(java.lang.String self)
split(CharSequence)
public static <T> T splitEachLine(java.lang.CharSequence self, java.lang.CharSequence regex, Closure<T> closure) throws java.io.IOException
self
- a CharSequenceregex
- the delimiting regular expressionclosure
- a closurejava.io.IOException
- if an error occursjava.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalidsplitEachLine(CharSequence, java.util.regex.Pattern, groovy.lang.Closure)
public static <T> T splitEachLine(java.lang.CharSequence self, java.util.regex.Pattern pattern, Closure<T> closure)
self
- a CharSequencepattern
- the regular expression Pattern for the delimiterclosure
- a closure@Deprecated public static <T> T splitEachLine(java.lang.String self, java.util.regex.Pattern pattern, Closure<T> closure) throws java.io.IOException
java.io.IOException
splitEachLine(CharSequence, java.util.regex.Pattern, groovy.lang.Closure)
@Deprecated public static <T> T splitEachLine(java.lang.String self, java.lang.String regex, Closure<T> closure) throws java.io.IOException
java.io.IOException
splitEachLine(CharSequence, java.util.regex.Pattern, groovy.lang.Closure)
public static java.lang.String stripIndent(java.lang.CharSequence self)
assert ' A\n B\nC' == ' A\n B\n C'.stripIndent()
self
- The CharSequence to strip the leading spaces fromstripIndent(String)
public static java.lang.String stripIndent(java.lang.CharSequence self, int numChars)
assert 'DEF\n456' == '''ABCDEF\n123456'''.stripIndent(3)
self
- The CharSequence to strip the characters fromnumChars
- The number of characters to strip@Deprecated public static java.lang.String stripIndent(java.lang.String self)
stripIndent(CharSequence)
@Deprecated public static java.lang.String stripIndent(java.lang.String self, int numChars)
stripIndent(CharSequence)
public static java.lang.String stripMargin(java.lang.CharSequence self)
assert 'ABC\n123\n456' == '''ABC |123 |456'''.stripMargin()
self
- The CharSequence to strip the margin fromstripMargin(CharSequence, char)
public static java.lang.String stripMargin(java.lang.CharSequence self, char marginChar)
assert 'ABC\n123\n456' == '''ABC *123 *456'''.stripMargin('*')
self
- The CharSequence to strip the margin frommarginChar
- Any character that serves as margin delimiterstripMargin(String, char)
public static java.lang.String stripMargin(java.lang.CharSequence self, java.lang.CharSequence marginChar)
self
- The CharSequence to strip the margin frommarginChar
- Any character that serves as margin delimiterstripMargin(String, String)
@Deprecated public static java.lang.String stripMargin(java.lang.String self)
stripMargin(CharSequence)
@Deprecated public static java.lang.String stripMargin(java.lang.String self, char marginChar)
stripMargin(CharSequence, char)
@Deprecated public static java.lang.String stripMargin(java.lang.String self, java.lang.String marginChar)
stripMargin(CharSequence, char)
public static java.lang.CharSequence take(java.lang.CharSequence self, int num)
num
elements from this CharSequence.
def text = "Groovy" assert text.take( 0 ) == '' assert text.take( 2 ) == 'Gr' assert text.take( 7 ) == 'Groovy'
self
- the original CharSequencenum
- the number of chars to take from this CharSequencenum
chars,
or else the whole CharSequence if it has less then num
elements.public static java.lang.String take(GString self, int num)
self
- the original GStringnum
- the number of chars to take from this GStringnum
chars,
or else the whole GString if it has less then num
elements.public static java.lang.CharSequence takeWhile(java.lang.CharSequence self, Closure condition)
def text = "Groovy" assert text.takeWhile{ it < 'A' } == '' assert text.takeWhile{ it < 'Z' } == 'G' assert text.takeWhile{ it != 'v' } == 'Groo' assert text.takeWhile{ it < 'z' } == 'Groovy'
self
- the original CharSequencecondition
- the closure that must evaluate to true to continue taking elementspublic static java.lang.String takeWhile(GString self, Closure condition)
self
- the original GStringcondition
- the closure that must evaluate to true to continue taking elementspublic static java.math.BigDecimal toBigDecimal(java.lang.CharSequence self)
self
- a CharSequencetoBigDecimal(String)
@Deprecated public static java.math.BigDecimal toBigDecimal(java.lang.String self)
toBigDecimal(CharSequence)
public static java.math.BigInteger toBigInteger(java.lang.CharSequence self)
self
- a CharSequencetoBigInteger(String)
@Deprecated public static java.math.BigInteger toBigInteger(java.lang.String self)
toBigInteger(CharSequence)
public static java.lang.Boolean toBoolean(java.lang.String self)
self
- a Stringpublic static java.lang.Character toCharacter(java.lang.String self)
self
- a Stringpublic static java.lang.Double toDouble(java.lang.CharSequence self)
self
- a CharSequencetoDouble(String)
@Deprecated public static java.lang.Double toDouble(java.lang.String self)
toDouble(CharSequence)
public static java.lang.Float toFloat(java.lang.CharSequence self)
self
- a CharSequencetoFloat(String)
@Deprecated public static java.lang.Float toFloat(java.lang.String self)
toFloat(CharSequence)
public static java.lang.Integer toInteger(java.lang.CharSequence self)
self
- a CharSequence@Deprecated public static java.lang.Integer toInteger(java.lang.String self)
toInteger(CharSequence)
public static java.util.List<java.lang.String> tokenize(java.lang.CharSequence self)
self
- a CharSequenceStringTokenizer.StringTokenizer(String)
public static java.util.List<java.lang.String> tokenize(java.lang.CharSequence self, java.lang.Character delimiter)
char pathSep = ':' assert "/tmp:/usr".tokenize(pathSep) == ["/tmp", "/usr"]
self
- a CharSequencedelimiter
- the delimiterStringTokenizer.StringTokenizer(String, String)
public static java.util.List<java.lang.String> tokenize(java.lang.CharSequence self, java.lang.CharSequence delimiters)
self
- a CharSequencedelimiters
- the delimitersStringTokenizer.StringTokenizer(String, String)
@Deprecated public static java.util.List<java.lang.String> tokenize(java.lang.String self)
tokenize(CharSequence)
@Deprecated public static java.util.List<java.lang.String> tokenize(java.lang.String self, java.lang.Character delimiter)
tokenize(CharSequence, Character)
@Deprecated public static java.util.List<java.lang.String> tokenize(java.lang.String self, java.lang.String delimiters)
tokenize(CharSequence, CharSequence)
public static java.util.List<java.lang.String> toList(java.lang.CharSequence self)
self
- a CharSequencetoSet(String)
@Deprecated public static java.util.List<java.lang.String> toList(java.lang.String self)
toList(CharSequence)
public static java.lang.Long toLong(java.lang.CharSequence self)
self
- a CharSequencetoLong(String)
@Deprecated public static java.lang.Long toLong(java.lang.String self)
toLong(CharSequence)
public static java.util.Set<java.lang.String> toSet(java.lang.CharSequence self)
self
- a CharSequencetoSet(String)
@Deprecated public static java.util.Set<java.lang.String> toSet(java.lang.String self)
toSet(CharSequence)
public static java.lang.Short toShort(java.lang.CharSequence self)
self
- a CharSequence@Deprecated public static java.lang.Short toShort(java.lang.String self)
toShort(CharSequence)
public static java.lang.String tr(java.lang.CharSequence self, java.lang.CharSequence sourceSet, java.lang.CharSequence replacementSet) throws java.lang.ClassNotFoundException
Here is an example which converts the vowels in a word from lower to uppercase:
assert 'hello'.tr('aeiou', 'AEIOU') == 'hEllO'A character range using regex-style syntax can also be used, e.g. here is an example which converts a word from lower to uppercase:
assert 'hello'.tr('a-z', 'A-Z') == 'HELLO'Hyphens at the start or end of sourceSet or replacementSet are treated as normal hyphens and are not considered to be part of a range specification. Similarly, a hyphen immediately after an earlier range is treated as a normal hyphen. So, '-x', 'x-' have no ranges while 'a-c-e' has the range 'a-c' plus the '-' character plus the 'e' character.
Unlike the unix tr command, Groovy's tr command supports reverse ranges, e.g.:
assert 'hello'.tr('z-a', 'Z-A') == 'HELLO'If replacementSet is smaller than sourceSet, then the last character from replacementSet is used as the replacement for all remaining source characters as shown here:
assert 'Hello World!'.tr('a-z', 'A') == 'HAAAA WAAAA!'If sourceSet contains repeated characters, the last specified replacement is used as shown here:
assert 'Hello World!'.tr('lloo', '1234') == 'He224 W4r2d!'The functionality provided by tr can be achieved using regular expressions but tr provides a much more compact notation and efficient implementation for certain scenarios.
self
- the CharSequence that is to be translatedsourceSet
- the set of characters to translate fromreplacementSet
- the set of replacement charactersjava.lang.ClassNotFoundException
StringUtil.tr(String, String, String)
@Deprecated public static java.lang.String tr(java.lang.String self, java.lang.String sourceSet, java.lang.String replacementSet) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
tr(CharSequence, CharSequence, CharSequence)
public static java.lang.String unexpand(java.lang.CharSequence self)
self
- A CharSequence to unexpandunexpand(String)
public static java.lang.String unexpand(java.lang.CharSequence self, int tabStop)
self
- A CharSequence to unexpandtabStop
- The number of spaces a tab represents@Deprecated public static java.lang.String unexpand(java.lang.String self)
unexpand(CharSequence)
@Deprecated public static java.lang.String unexpand(java.lang.String self, int tabStop)
unexpand(CharSequence, int)
public static java.lang.String unexpandLine(java.lang.CharSequence self, int tabStop)
self
- A line to unexpandtabStop
- The number of spaces a tab represents@Deprecated public static java.lang.String unexpandLine(java.lang.String self, int tabStop)
tokenize(CharSequence)