Class StringGroovyMethods
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 SummaryConstructors Constructor Description StringGroovyMethods()
- 
Method SummaryModifier and Type Method Description static java.lang.StringBuilderappend(java.lang.StringBuilder sb, GStringImpl gs)Append the GString to the StringBuilder using a more efficient approach than Java's default approach for a CharSequence.static booleanasBoolean(java.lang.CharSequence chars)Coerces a CharSequence to a boolean value.static booleanasBoolean(java.util.regex.Matcher matcher)Coerces a Matcher instance to a boolean value.static <T> TasType(GString self, java.lang.Class<T> c)Converts the GString to a File, or delegates to the defaultDefaultGroovyMethods.asType(Object,Class).static <T> TasType(java.lang.CharSequence self, java.lang.Class<T> c)Provides a method to perform custom 'dynamic' type conversion to the given class using theasoperator.static <T> TasType(java.lang.String self, java.lang.Class<T> c)Provides a method to perform custom 'dynamic' type conversion to the given class using theasoperator.static java.util.regex.PatternbitwiseNegate(java.lang.CharSequence self)Turns a CharSequence into a regular expression Pattern.static java.lang.Stringcapitalize(java.lang.CharSequence self)Convenience method to capitalize the first letter of a CharSequence (typically the first letter of a word).static java.lang.Stringcenter(java.lang.CharSequence self, java.lang.Number numberOfChars)Pads a CharSequence to a minimum length specified bynumberOfCharsby adding the space character around it as many times as needed so that it remains centered.static java.lang.Stringcenter(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)Pad a CharSequence to a minimum length specified bynumberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.static java.lang.StringcollectReplacements(java.lang.String self, Closure<java.lang.String> transform)Iterates through this String a character at a time collecting either the original character or a transformed replacement String.static java.lang.StringcollectReplacements(java.lang.String self, java.util.List<java.util.function.Function<java.lang.Character,java.util.Optional<java.lang.String>>> transforms)Iterates through this String a character at a time collecting either the original character or a transformed replacement String.static booleancontains(java.lang.CharSequence self, java.lang.CharSequence text)Provides an implementation of contains() likeCollection.contains(Object)to make CharSequences more polymorphic.static booleancontainsIgnoreCase(java.lang.CharSequence self, java.lang.CharSequence searchString)Checks whether this CharSequence contains thesearchStringignoring the caseConsiderations.static intcount(java.lang.CharSequence self, java.lang.CharSequence text)Counts the number of occurrences of a sub CharSequence.static java.lang.Stringdenormalize(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.Stringdrop(GString self, int num)A GString variant of the equivalent CharSequence method.static java.lang.CharSequencedrop(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.Stringdrop(java.lang.String self, int num)A String variant of the equivalent CharSequence method.static java.lang.StringdropRight(GString self, int num)A GString variant of the equivalent CharSequence methoddropRight(CharSequence,int).static java.lang.CharSequencedropRight(java.lang.CharSequence self, int num)Returns new CharSequence after removing the rightnumchars.static java.lang.StringdropRight(java.lang.String self, int num)A String variant of the equivalent CharSequence methoddropRight(CharSequence,int).static java.lang.StringdropWhile(GString self, Closure condition)A GString variant of the equivalent CharSequence method.static java.lang.StringdropWhile(java.lang.CharSequence self, Closure condition)Creates 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.CharSequencedropWhile$$bridge(java.lang.CharSequence self, Closure condition)Deprecated.static <T> TeachLine(java.lang.CharSequence self, int firstLine, Closure<T> closure)Iterates through this CharSequence line by line.static <T> TeachLine(java.lang.CharSequence self, Closure<T> closure)Iterates through this CharSequence line by line.static java.lang.StringeachMatch(java.lang.String self, java.lang.String regex, Closure closure)Process each regex group matched substring of the given string.static java.lang.StringeachMatch(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)Processes each regex group matched substring of the given pattern.static <T extends java.lang.CharSequence>
 TeachMatch(T self, java.lang.CharSequence regex, Closure closure)Processes each regex group matched substring of the given CharSequence.static <T extends java.lang.CharSequence>
 TeachMatch(T self, java.util.regex.Pattern pattern, Closure closure)Processes each regex group matched substring of the given pattern.static booleanendsWithAny(java.lang.CharSequence self, java.lang.CharSequence... suffixes)Tests if this CharSequence ends with any specified suffixes.static booleanendsWithIgnoreCase(java.lang.CharSequence self, java.lang.CharSequence searchString)Checks whether this CharSequence ends with thesearchStringignoring the case considerations.static java.lang.Stringexpand(java.lang.CharSequence self)Expands all tabs into spaces with tabStops of size 8.static java.lang.Stringexpand(java.lang.CharSequence self, int tabStop)Expands all tabs into spaces.static java.lang.StringexpandLine(java.lang.CharSequence self, int tabStop)Expands all tabs into spaces.static java.lang.Stringfind(java.lang.CharSequence self, java.lang.CharSequence regex)Finds the first occurrence of a regular expression String within a String.static java.lang.Stringfind(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.Stringfind(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.Stringfind(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.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.lang.StringgetAt(GString self, int index)Supports the subscript operator for GString.static java.lang.StringgetAt(GString self, IntRange range)Supports the range subscript operator for GString with IntRange.static java.lang.StringgetAt(GString self, Range range)Supports the range subscript operator for GString.static java.lang.CharSequencegetAt(java.lang.CharSequence self, int index)Supports the subscript operator for CharSequence.static java.lang.StringgetAt(java.lang.CharSequence self, EmptyRange range)Supports the range subscript operator for CharSequence or StringBuffer with EmptyRangestatic java.lang.CharSequencegetAt(java.lang.CharSequence self, IntRange range)Supports the range subscript operator for CharSequence with IntRange.static java.lang.CharSequencegetAt(java.lang.CharSequence self, Range range)Supports the range subscript operator for CharSequence.static java.lang.StringgetAt(java.lang.CharSequence self, java.util.Collection indices)Selects a List of characters from a CharSequence using a Collection to identify the indices to be selected.static java.lang.StringgetAt(java.lang.String self, int index)Supports the subscript operator for String.static java.lang.StringgetAt(java.lang.String self, IntRange range)Supports the range subscript operator for String with IntRange.static java.lang.StringgetAt(java.lang.String self, Range range)Supports the range subscript operator for String.static java.lang.ObjectgetAt(java.util.regex.Matcher self, int index)Supports the subscript operator, e.g.static java.util.ListgetAt(java.util.regex.Matcher self, java.util.Collection indices)Selects a List of values from a Matcher using a Collection to identify the indices to be selected.static char[]getChars(java.lang.CharSequence self)Converts the given CharSequence into an array of characters.static intgetCount(java.util.regex.Matcher self)Finds the number of Strings matched to the given Matcher.static booleanhasGroup(java.util.regex.Matcher self)Checks whether a Matcher contains a group or not.static booleanisAllWhitespace(java.lang.CharSequence self)Returns true if a CharSequence only contains whitespace characters.static java.lang.BooleanisAtLeast(java.lang.String left, java.lang.String right)Compares a String representing a number to another.static booleanisBigDecimal(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a BigDecimal.static booleanisBigInteger(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a BigInteger.static booleanisBlank(java.lang.CharSequence self)Tests if this CharSequence is blank.static booleanisCase(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 booleanisCase(java.util.regex.Pattern caseValue, java.lang.Object switchValue)'Case' implementation for thePatternclass, which allows testing a String against a number of regular expressions.static booleanisDouble(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Double.static booleanisFloat(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Float.static booleanisInteger(java.lang.CharSequence self)Determines if a CharSequence can be parsed as an Integer.static booleanisLong(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Long.static booleanisNumber(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Number.static java.util.Iteratoriterator(java.util.regex.Matcher self)Returns anIteratorwhich traverses each match.static java.lang.StringBuilderleftShift(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.StringBufferleftShift(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.StringBuilderleftShift(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.StringBufferleftShift(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 booleanmatches(java.lang.CharSequence self, java.util.regex.Pattern pattern)Determines if a CharSequence matches the given regular expression.static booleanmatchesPartially(java.util.regex.Matcher self)Given a matcher that matches a string against a pattern, returns true when the string matches the pattern or if a longer string, could match the pattern.static java.lang.Stringminus(java.lang.CharSequence self, java.lang.Object target)Removes a part of a CharSequence by replacing the first occurrence of target within self with empty string and returns the result.static java.lang.Stringminus(java.lang.CharSequence self, java.util.regex.Pattern pattern)Removes a part of a CharSequence.static java.lang.Stringmultiply(java.lang.CharSequence self, java.lang.Number factor)Repeats a CharSequence a certain number of times.static java.lang.Stringnext(java.lang.CharSequence self)Overloads the++operator for the class CharSequence.static java.lang.Stringnormalize(java.lang.CharSequence self)Returns a String with linefeeds and carriage returns normalized to linefeeds.static java.lang.StringpadLeft(java.lang.CharSequence self, java.lang.Number numberOfChars)Pads a CharSequence to a minimum length specified bynumberOfCharsby adding the space character to the left as many times as needed.static java.lang.StringpadLeft(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)Pads a CharSequence to a minimum length specified bynumberOfChars, adding the supplied padding CharSequence as many times as needed to the left.static java.lang.StringpadRight(java.lang.CharSequence self, java.lang.Number numberOfChars)Pads a CharSequence to a minimum length specified bynumberOfCharsby adding the space character to the right as many times as needed.static java.lang.StringpadRight(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)Pads a CharSequence to a minimum length specified bynumberOfChars, adding the supplied padding CharSequence as many times as needed to the right.static java.lang.Stringplus(java.lang.CharSequence left, java.lang.Object right)Appends the String representation of the given operand to this CharSequence.static java.lang.Stringplus(java.lang.Number left, java.lang.String right)Appends a String to the string representation of this number.static java.lang.Stringplus(java.lang.StringBuffer left, java.lang.String right)Appends a String to this StringBuffer.static java.lang.Stringplus(java.lang.String left, java.lang.CharSequence right)Appends the String representation of the given operand to this string.static java.lang.Stringprevious(java.lang.CharSequence self)Overloads the--operator for the class CharSequence.static voidputAt(java.lang.StringBuffer self, EmptyRange range, java.lang.Object value)Supports the range subscript operator for StringBuffer.static voidputAt(java.lang.StringBuffer self, IntRange range, java.lang.Object value)Supports the range subscript operator for StringBuffer.static java.util.List<java.lang.String>readLines(java.lang.CharSequence self)Returns the lines of a CharSequence as a List of String.static java.lang.Stringreplace(java.lang.CharSequence self, int capacity, java.util.Map<java.lang.CharSequence,java.lang.CharSequence> replacements)Replaces all occurrences of replacement CharSequences (supplied via a map) within a provided CharSequence with control over the internally created StringBuilder's capacity.static java.lang.Stringreplace(java.lang.CharSequence self, java.util.Map<java.lang.CharSequence,java.lang.CharSequence> replacements)Replaces all occurrences of replacement CharSequences (supplied via a map) within a provided CharSequence.static java.lang.StringreplaceAll(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.StringreplaceAll(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.StringreplaceAll(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.StringreplaceAll(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.StringreplaceFirst(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.StringreplaceFirst(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.StringreplaceFirst(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.StringreplaceFirst(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.Stringreverse(java.lang.CharSequence self)Creates a String which is the reverse (backwards) of this CharSequencestatic voidsetIndex(java.util.regex.Matcher self, int index)Sets the position of the given Matcher to the given index.static intsize(java.lang.CharSequence self)Provides the standard Groovysize()method forCharSequence.static intsize(java.lang.String self)Deprecated.static intsize(java.lang.StringBuffer self)Deprecated.static longsize(java.util.regex.Matcher self)Provides the standard Groovysize()method forMatcher.static java.lang.String[]split(java.lang.CharSequence self)Splits a CharSequence (with whitespace as delimiter).static <T> TsplitEachLine(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> TsplitEachLine(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 booleanstartsWithAny(java.lang.CharSequence self, java.lang.CharSequence... prefixes)Tests if this CharSequence starts with any specified prefixes.static booleanstartsWithIgnoreCase(java.lang.CharSequence self, java.lang.CharSequence searchString)Checks whether this CharSequence starts with thesearchStringignoring the case considerations.static java.lang.StringstripIndent(java.lang.CharSequence self)Strips leading spaces from every line in a CharSequence.static java.lang.StringstripIndent(java.lang.CharSequence self, boolean forceGroovyBehavior)Same logic asstripIndent(CharSequence)ifforceGroovyBehavioristrue, otherwise Java 13'sstripIndentwill be invoked.static java.lang.StringstripIndent(java.lang.CharSequence self, int numChars)StripsnumCharsleading characters from every line in a CharSequence.static java.lang.StringstripMargin(java.lang.CharSequence self)Strips leading whitespace/control characters followed by '|' from every line in a CharSequence.static java.lang.StringstripMargin(java.lang.CharSequence self, char marginChar)Strips leading whitespace/control characters followed bymarginCharfrom every line in a CharSequence.static java.lang.StringstripMargin(java.lang.CharSequence self, java.lang.CharSequence marginChar)Strips leading whitespace/control characters followed bymarginCharfrom every line in a CharSequence.static java.lang.Stringtake(GString self, int num)A GString variant of the equivalent CharSequence method.static java.lang.CharSequencetake(java.lang.CharSequence self, int num)Returns the firstnumelements from this CharSequence.static java.lang.Stringtake(java.lang.String self, int num)A String variant of the equivalent CharSequence method.static java.lang.StringtakeAfter(GString self, java.lang.CharSequence searchString)A GString variant of the equivalent CharSequence methodtakeAfter(CharSequence,CharSequence).static java.lang.CharSequencetakeAfter(java.lang.CharSequence self, java.lang.CharSequence searchString)Returns theCharSequencethat exists after the first occurrence of the givensearchStringin this CharSequence.static java.lang.StringtakeAfter(java.lang.String self, java.lang.CharSequence searchString)A String variant of the equivalent CharSequence methodtakeAfter(CharSequence,CharSequence).static java.lang.StringtakeBefore(GString self, java.lang.String searchString)A GString variant of the equivalent CharSequence methodtakeBefore(CharSequence,CharSequence).static java.lang.CharSequencetakeBefore(java.lang.CharSequence self, java.lang.CharSequence searchString)Returns theCharSequencethat exists before the first occurrence of the givensearchStringin this CharSequence.static java.lang.StringtakeBefore(java.lang.String self, java.lang.String searchString)A String variant of the equivalent CharSequence methodtakeBefore(CharSequence,CharSequence).static java.lang.StringtakeBetween(GString self, java.lang.CharSequence enclosure)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence).static java.lang.StringtakeBetween(GString self, java.lang.CharSequence enclosure, int occurrence)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,int).static java.lang.StringtakeBetween(GString self, java.lang.CharSequence from, java.lang.CharSequence to)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence).static java.lang.StringtakeBetween(GString self, java.lang.CharSequence from, java.lang.CharSequence to, int occurrence)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence,int).static java.lang.CharSequencetakeBetween(java.lang.CharSequence self, java.lang.CharSequence enclosure)Takes the characters between the first occurrence of the two subsequentenclosurestrings.static java.lang.CharSequencetakeBetween(java.lang.CharSequence self, java.lang.CharSequence enclosure, int occurrence)Takes the characters between nth (specified by occurrence) pair ofenclosurestrings.static java.lang.CharSequencetakeBetween(java.lang.CharSequence self, java.lang.CharSequence from, java.lang.CharSequence to)Returns the CharSequence that is in between the first occurrence of the givenfromandtoCharSequences and empty if the unavailable inputs are given.static java.lang.CharSequencetakeBetween(java.lang.CharSequence self, java.lang.CharSequence from, java.lang.CharSequence to, int occurrence)Returns the CharSequence that is in between the given the nth (specified by occurrence) pair offromandtoCharSequences and empty if the unavailable inputs are given.static java.lang.StringtakeBetween(java.lang.String self, java.lang.CharSequence enclosure)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence).static java.lang.StringtakeBetween(java.lang.String self, java.lang.CharSequence enclosure, int occurrence)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,int).static java.lang.StringtakeBetween(java.lang.String self, java.lang.CharSequence from, java.lang.CharSequence to)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence).static java.lang.StringtakeBetween(java.lang.String self, java.lang.CharSequence from, java.lang.CharSequence to, int occurrence)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence,int).static java.lang.StringtakeRight(GString self, int num)A String variant of the equivalent CharSequence methodtakeRight(CharSequence,int).static java.lang.CharSequencetakeRight(java.lang.CharSequence self, int num)Returns the lastnumelements from this CharSequence.static java.lang.StringtakeRight(java.lang.String self, int num)A GString variant of the equivalent CharSequence methodtakeRight(CharSequence,int).static java.lang.StringtakeWhile(GString self, Closure condition)A GString variant of the equivalent GString method.static java.lang.StringtakeWhile(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.CharSequencetakeWhile$$bridge(java.lang.CharSequence self, Closure condition)Deprecated.static java.math.BigDecimaltoBigDecimal(java.lang.CharSequence self)Parses a CharSequence into a BigDecimalstatic java.math.BigIntegertoBigInteger(java.lang.CharSequence self)Parses a CharSequence into a BigIntegerstatic java.lang.BooleantoBoolean(java.lang.String self)Converts the given string into a Boolean object.static java.lang.CharactertoCharacter(java.lang.String self)Converts the given string into a Character object using the first character in the string.static java.lang.DoubletoDouble(java.lang.CharSequence self)Parses a CharSequence into a Double.static java.lang.FloattoFloat(java.lang.CharSequence self)Parses a CharSequence into a Float.static java.lang.IntegertoInteger(java.lang.CharSequence self)Parses a CharSequence into an Integer.static java.util.List<java.lang.String>tokenize(java.lang.CharSequence self)Tokenizes a CharSequence (with a whitespace as the delimiter).static java.util.List<java.lang.String>tokenize(java.lang.CharSequence self, java.lang.Character delimiter)Tokenizes a CharSequence based on the given character delimiter.static java.util.List<java.lang.String>tokenize(java.lang.CharSequence self, java.lang.CharSequence delimiters)Tokenizes a CharSequence based on the given CharSequence.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.lang.LongtoLong(java.lang.CharSequence self)Parses a CharSequence into a Longstatic 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.lang.ShorttoShort(java.lang.CharSequence self)Parses a CharSequence into a Short.static java.lang.Stringtr(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.Stringuncapitalize(java.lang.CharSequence self)Convenience method to uncapitalize the first letter of a CharSequence (typically the first letter of a word).static java.lang.Stringunexpand(java.lang.CharSequence self)Replaces sequences of whitespaces with tabs using tabStops of size 8.static java.lang.Stringunexpand(java.lang.CharSequence self, int tabStop)Replaces sequences of whitespaces with tabs.static java.lang.StringunexpandLine(java.lang.CharSequence self, int tabStop)Replaces sequences of whitespaces with tabs within a line.Methods inherited from class org.codehaus.groovy.runtime.DefaultGroovyMethodsSupportcloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequiredMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Constructor Details- 
StringGroovyMethodspublic StringGroovyMethods()
 
- 
- 
Method Details- 
asBooleanpublic static boolean asBoolean(java.lang.CharSequence chars)Coerces a CharSequence to a boolean value. A sequence string is coerced tofalseif it is of length 0, and totrueotherwise.- Parameters:
- chars- the character sequence
- Returns:
- the boolean value
- Since:
- 1.7.0
 
- 
asBooleanpublic static boolean asBoolean(java.util.regex.Matcher matcher)Coerces a Matcher instance to a boolean value.- Parameters:
- matcher- the matcher
- Returns:
- the boolean value
- Since:
- 1.7.0
 
- 
asTypepublic 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 theasoperator.- Parameters:
- self- a CharSequence
- c- the desired class
- Returns:
- the converted object
- Since:
- 1.8.2
- See Also:
- asType(String,Class)
 
- 
asTypeConverts the GString to a File, or delegates to the defaultDefaultGroovyMethods.asType(Object,Class).- Parameters:
- self- a GString
- c- the desired class
- Returns:
- the converted object
- Since:
- 1.5.0
 
- 
asTypepublic 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 theasoperator.Example: '123' as DoubleBy default, the following types are supported: - List
- BigDecimal
- BigInteger
- Long
- Integer
- Short
- Byte
- Character
- Double
- Float
- File
- Subclasses of Enum
 DefaultGroovyMethods.asType(Object,Class).- Parameters:
- self- a String
- c- the desired class
- Returns:
- the converted object
- Since:
- 1.0
 
- 
bitwiseNegatepublic static java.util.regex.Pattern bitwiseNegate(java.lang.CharSequence self)Turns a CharSequence into a regular expression Pattern.- Parameters:
- self- a String to convert into a regular expression
- Returns:
- the regular expression pattern
- Since:
- 1.8.2
 
- 
appendAppend the GString to the StringBuilder using a more efficient approach than Java's default approach for a CharSequence.- Parameters:
- sb- a StringBuilder
- gs- a GStringImpl
- Returns:
- the StringBuilder
- Since:
- 3.0.8
 
- 
uncapitalizepublic 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). Example usage: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(' ')- Parameters:
- self- The CharSequence to uncapitalize
- Returns:
- A String containing the uncapitalized toString() of the CharSequence
- Since:
- 2.4.8
 
- 
capitalizepublic 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). Example usage:assert 'h'.capitalize() == 'H' assert 'hello'.capitalize() == 'Hello' assert 'hello world'.capitalize() == 'Hello world' assert 'Hello World' == 'hello world'.split(' ').collect{ it.capitalize() }.join(' ')- Parameters:
- self- The CharSequence to capitalize
- Returns:
- A String containing the capitalized toString() of the CharSequence
- Since:
- 1.8.2
 
- 
centerpublic static java.lang.String center(java.lang.CharSequence self, java.lang.Number numberOfChars)Pads a CharSequence to a minimum length specified bynumberOfCharsby adding the space character around it as many times as needed so that it remains centered.If the String is already the same size or bigger than the target numberOfChars, then the original String is returned. An example:['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6) + '|' }will produce output like:| A | | BB | | CCC | | DDDD | - Parameters:
- self- a CharSequence object
- numberOfChars- the total minimum number of characters of the result
- Returns:
- the centered toString() of this CharSequence with padded characters around it
- Since:
- 1.8.2
 
- 
centerpublic 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 bynumberOfChars, appending the supplied padding CharSequence around the original as many times as needed keeping it centered. If the String is already the same size or bigger than the targetnumberOfChars, then the original String is returned. An example:['A', 'BB', 'CCC', 'DDDD'].each{ println '|' + it.center(6, '+') + '|' }will produce output like:|++A+++| |++BB++| |+CCC++| |+DDDD+| - Parameters:
- self- a CharSequence object
- numberOfChars- the total minimum number of characters of the resulting CharSequence
- padding- the characters used for padding
- Returns:
- the centered toString() of this CharSequence with padded characters around it
- Since:
- 1.8.2
 
- 
containspublic static boolean contains(java.lang.CharSequence self, java.lang.CharSequence text)Provides an implementation of contains() likeCollection.contains(Object)to make CharSequences more polymorphic.- Parameters:
- self- a CharSequence
- text- the CharSequence to look for
- Returns:
- true if this CharSequence contains the given text
- Since:
- 1.8.2
 
- 
countpublic static int count(java.lang.CharSequence self, java.lang.CharSequence text)Counts the number of occurrences of a sub CharSequence.- Parameters:
- self- a CharSequence
- text- a sub CharSequence
- Returns:
- the number of occurrences of the given CharSequence inside this CharSequence
- Since:
- 1.8.2
 
- 
denormalizepublic 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.- Parameters:
- self- a CharSequence object
- Returns:
- the denormalized toString() of this CharSequence
- Since:
- 1.8.2
 
- 
droppublic 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.def text = "Groovy" assert text.drop( 0 ) == 'Groovy' assert text.drop( 2 ) == 'oovy' assert text.drop( 7 ) == ''- Parameters:
- self- the original CharSequence
- num- the number of characters to drop from this String
- Returns:
- a CharSequence consisting of all characters except the first numones, or else an empty String, if this CharSequence has less thannumcharacters.
- Since:
- 1.8.1
 
- 
dropA GString variant of the equivalent CharSequence method.- Parameters:
- self- the original GString
- num- the number of characters to drop from this GString
- Returns:
- a String consisting of all characters except the first numones, or else an empty String, if the toString() of this GString has less thannumcharacters.
- Since:
- 2.3.7
- See Also:
- drop(String,int)
 
- 
droppublic static java.lang.String drop(java.lang.String self, int num)A String variant of the equivalent CharSequence method.- Parameters:
- self- the original String
- num- the number of characters to drop from this String
- Returns:
- a String consisting of all characters except the first numones, or else an empty String, if the String has less thannumcharacters.
- Since:
- 2.5.5
- See Also:
- drop(CharSequence,int)
 
- 
dropWhileCreates 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.def text = "Groovy" assert text.dropWhile{ false } == 'Groovy' assert text.dropWhile{ true } == '' assert text.dropWhile{ it<'Z' } == 'roovy' assert text.dropWhile{ it != 'v' } == 'vy'- Parameters:
- self- the original CharSequence
- condition- the closure that while continuously evaluating to true will cause us to drop elements from the front of the original CharSequence
- Returns:
- the shortest suffix of the given CharSequence such that the given closure condition evaluates to true for each element dropped from the front of the CharSequence
- Since:
- 2.0.0
 
- 
dropWhile$$bridge@Deprecated public static java.lang.CharSequence dropWhile$$bridge(java.lang.CharSequence self, Closure condition)Deprecated.
- 
dropWhileA GString variant of the equivalent CharSequence method.- Parameters:
- self- the original GString
- condition- the closure that while continuously evaluating to true will cause us to drop elements from the front of the original GString
- Returns:
- the shortest suffix of the given GString such that the given closure condition evaluates to true for each element dropped from the front of the CharSequence
- Since:
- 2.3.7
- See Also:
- dropWhile(CharSequence,Closure)
 
- 
eachLinepublic static <T> T eachLine(java.lang.CharSequence self, Closure<T> closure) throws java.io.IOExceptionIterates through this CharSequence line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.- Parameters:
- self- a CharSequence
- closure- a closure
- Returns:
- the last value returned by the closure
- Throws:
- java.io.IOException- if an error occurs
- Since:
- 1.8.2
 
- 
eachLinepublic static <T> T eachLine(java.lang.CharSequence self, int firstLine, Closure<T> closure) throws java.io.IOExceptionIterates through this CharSequence line by line. Each line is passed to the given 1 or 2 arg closure. If a 2 arg closure is found the line count is passed as the second argument.- Parameters:
- self- a CharSequence
- firstLine- 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)
- Returns:
- the last value returned by the closure
- Throws:
- java.io.IOException- if an error occurs
- Since:
- 1.8.2
 
- 
collectReplacementspublic static java.lang.String collectReplacements(java.lang.String self, Closure<java.lang.String> transform)Iterates through this String a character at a time collecting either the original character or a transformed replacement String. ThetransformClosure should returnnullto indicate that no transformation is required for the given character.assert "Groovy".collectReplacements{ it == 'o' ? '_O_' : null } == 'Gr_O__O_vy' assert "Groovy".collectReplacements{ it.equalsIgnoreCase('O') ? '_O_' : null } == 'Gr_O__O_vy' assert "Groovy".collectReplacements{ char c->c == 'o' ? '_O_' : null } == 'Gr_O__O_vy' assert "Groovy".collectReplacements{ Character c->c == 'o' ? '_O_' : null } == 'Gr_O__O_vy' assert "B&W".collectReplacements{it == '&' ? '&' : null} == 'B&W'- Parameters:
- self- the original String
- Returns:
- A new string in which all characters that require escaping
         have been replaced with the corresponding replacements
         as determined by the transformClosure.
- Since:
- 2.1.0
 
- 
collectReplacementspublic static java.lang.String collectReplacements(java.lang.String self, java.util.List<java.util.function.Function<java.lang.Character,java.util.Optional<java.lang.String>>> transforms)Iterates through this String a character at a time collecting either the original character or a transformed replacement String. The return value is anOptionaleither having a value equal to the transformed replacement String orempty()to indicate that no transformation is required.import java.util.function.Function import static java.util.Optional.* Function<Character, Optional<String>> xform1 = s -> s == 'o' ? of('_O') : empty() Function<Character, Optional<String>> xform2 = { it == 'G' ? of('G_') : empty() } assert "Groovy".collectReplacements([xform1, xform2]) == 'G_r_O_Ovy'- Parameters:
- self- the original String
- transforms- one or more transforms which potentially convert a single character to a transformed string
- Returns:
- A new string in which all characters that require escaping
         have been replaced with the corresponding replacements
         as determined by the transformfunction.
- Since:
- 3.0.6
 
- 
eachMatchpublic static <T extends java.lang.CharSequence> T eachMatch(T self, java.lang.CharSequence regex, Closure closure)Processes each regex group matched substring of the given CharSequence. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.- Parameters:
- self- the source CharSequence
- regex- a Regex CharSequence
- closure- a closure with one parameter or as many parameters as groups
- Returns:
- the source CharSequence
- Since:
- 1.8.2
- See Also:
- eachMatch(String,String,Closure)
 
- 
eachMatchpublic static <T extends java.lang.CharSequence> T eachMatch(T self, java.util.regex.Pattern pattern, Closure closure)Processes each regex group matched substring of the given pattern. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.- Parameters:
- self- the source CharSequence
- pattern- a regex Pattern
- closure- a closure with one parameter or as many parameters as groups
- Returns:
- the source CharSequence
- Since:
- 1.8.2
- See Also:
- eachMatch(String,Pattern,Closure)
 
- 
eachMatchpublic static java.lang.String eachMatch(java.lang.String self, java.util.regex.Pattern pattern, Closure closure)Processes each regex group matched substring of the given pattern. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.- Parameters:
- self- the source string
- pattern- a regex Pattern
- closure- a closure with one parameter or as many parameters as groups
- Returns:
- the source string
- Since:
- 1.6.1
 
- 
eachMatchpublic 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. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group.- Parameters:
- self- the source string
- regex- a Regex string
- closure- a closure with one parameter or as many parameters as groups
- Returns:
- the source string
- Since:
- 1.6.0
 
- 
expandpublic static java.lang.String expand(java.lang.CharSequence self)Expands all tabs into spaces with tabStops of size 8.- Parameters:
- self- A CharSequence to expand
- Returns:
- The expanded toString() of this CharSequence
- Since:
- 1.8.2
 
- 
expandpublic static java.lang.String expand(java.lang.CharSequence self, int tabStop)Expands all tabs into spaces. If the CharSequence has multiple lines, expand each line - restarting tab stops at the start of each line.- Parameters:
- self- A CharSequence to expand
- tabStop- The number of spaces a tab represents
- Returns:
- The expanded toString() of this CharSequence
- Since:
- 1.8.2
 
- 
expandLinepublic static java.lang.String expandLine(java.lang.CharSequence self, int tabStop)Expands all tabs into spaces. Assumes the CharSequence represents a single line of text.- Parameters:
- self- A line to expand
- tabStop- The number of spaces a tab represents
- Returns:
- The expanded toString() of this CharSequence
- Since:
- 1.8.2
 
- 
findpublic 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. If the regex doesn't match, null will be returned.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 matchassert "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/) == "10292-0098"- Parameters:
- self- a CharSequence
- regex- the capturing regex
- Returns:
- a String containing the matched portion, or null if the regex doesn't match
- Since:
- 1.8.2
- See Also:
- find(CharSequence,Pattern)
 
- 
findpublic 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. If the regex doesn't match, the closure will not be called and find will return null.- Parameters:
- self- a CharSequence
- regex- the capturing regex CharSequence
- closure- the closure that will be passed the full match, plus each of the capturing groups (if any)
- Returns:
- a String containing the result of calling the closure (calling toString() if needed), or null if the regex pattern doesn't match
- Since:
- 1.8.2
- See Also:
- find(CharSequence,Pattern,Closure)
 
- 
findpublic 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. If the pattern doesn't match, null will be returned.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 useeachMatch.- Parameters:
- self- a CharSequence
- pattern- the compiled regex Pattern
- Returns:
- a String containing the matched portion, or null if the regex pattern doesn't match
- Since:
- 1.8.2
 
- 
findpublic 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. If the regex doesn't match, the closure will not be called and find will return null.For example, if the pattern doesn't match, the result is null: assert "New York, NY".find(~/\d{5}/) { matchIf 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:->return "-$match-"} == nullassert "New York, NY 10292-0098".find(~/\d{5}/) { matchIf we have capture groups in our expression, our closure has one parameter for the match, followed by one for each of the capture groups:->return "-$match-"} == "-10292-"assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFourIf 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 match == "10292-0098" assert zip == "10292" assert plusFour == "0098" return zip } == "10292"assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { arrayIf 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 array[0] == "10292-0098" assert array[1] == "10292" assert array[2] == "0098" return array[1] } == "10292"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"- Parameters:
- self- a CharSequence
- pattern- the compiled regex Pattern
- closure- the closure that will be passed the full match, plus each of the capturing groups (if any)
- Returns:
- a String containing the result of calling the closure (calling toString() if needed), or null if the regex pattern doesn't match
- Since:
- 1.8.2
 
- 
findAllpublic 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.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/) == expected If you need to work with capture groups, then use the closure version of this method or use Groovy's matcher operators or useeachMatch.- Parameters:
- self- a CharSequence
- regex- the capturing regex CharSequence
- Returns:
- a List containing all full matches of the regex within the CharSequence, an empty list will be returned if there are no matches
- Since:
- 1.8.2
- See Also:
- findAll(CharSequence,Pattern)
 
- 
findAllpublic 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. Any matches are passed to the specified closure. The closure is expected to have the full match in the first parameter. If there are any capture groups, they will be placed in subsequent parameters.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, firstWordAny regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:->return firstWord } == []assert "I could not, would not, with a fox.".findAll(/.ould/) { matchIf there are capture groups, the first parameter will be the match followed by one parameter for each capture group:->"${match}n't"} == ["couldn't", "wouldn't"]def orig = "There's a Wocket in my Pocket" assert orig.findAll(/(.)ocket/) { match, firstLetter->"$firstLetter>$match" } == ["W>Wocket", "P>Pocket"]- Parameters:
- self- a CharSequence
- regex- the capturing regex CharSequence
- closure- will be passed the full match plus each of the capturing groups (if any)
- Returns:
- a List containing all results from calling the closure with each full match (and potentially capturing groups) of the regex within the CharSequence, an empty list will be returned if there are no matches
- Since:
- 1.8.2
- See Also:
- findAll(CharSequence,Pattern,Closure)
 
- 
findAllpublic 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.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 - Parameters:
- self- a CharSequence
- pattern- the compiled regex Pattern
- Returns:
- a List containing all full matches of the Pattern within the CharSequence, an empty list will be returned if there are no matches
- Since:
- 1.8.2
 
- 
findAllpublic 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. Any matches are passed to the specified closure. The closure is expected to have the full match in the first parameter. If there are any capture groups, they will be placed in subsequent parameters.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, firstWordAny regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:->return firstWord } == []assert "I could not, would not, with a fox.".findAll(~/.ould/) { matchIf there are capture groups, the first parameter will be the match followed by one parameter for each capture group:->"${match}n't"} == ["couldn't", "wouldn't"]def orig = "There's a Wocket in my Pocket" assert orig.findAll(~/(.)ocket/) { match, firstLetter->"$firstLetter>$match" } == ["W>Wocket", "P>Pocket"]- Parameters:
- self- a CharSequence
- pattern- the compiled regex Pattern
- closure- will be passed the full match plus each of the capturing groups (if any)
- Returns:
- a List containing all results from calling the closure with each full match (and potentially capturing groups) of the regex pattern within the CharSequence, an empty list will be returned if there are no matches
- Since:
- 1.8.2
 
- 
getAtpublic static java.lang.String getAt(java.lang.CharSequence self, java.util.Collection indices)Selects a List of characters from a CharSequence using a Collection to identify the indices to be selected.- Parameters:
- self- a CharSequence
- indices- a Collection of indices
- Returns:
- a String consisting of the characters at the given indices
- Since:
- 1.0
 
- 
getAtSupports the range subscript operator for CharSequence or StringBuffer with EmptyRange- Parameters:
- self- a CharSequence
- range- an EmptyRange
- Returns:
- the empty String
- Since:
- 1.5.0
 
- 
getAtpublic static java.lang.CharSequence getAt(java.lang.CharSequence self, int index)Supports the subscript operator for CharSequence.- Parameters:
- self- a CharSequence
- index- the index of the Character to get
- Returns:
- the Character at the given index
- Since:
- 1.0
 
- 
getAtSupports the subscript operator for GString.- Parameters:
- self- a GString
- index- the index of the Character to get
- Returns:
- the Character at the given index
- Since:
- 2.3.7
 
- 
getAtSupports the range subscript operator for CharSequence with IntRange.- Parameters:
- self- a CharSequence
- range- an IntRange
- Returns:
- the subsequence CharSequence
- Since:
- 1.0
 
- 
getAtSupports the range subscript operator for GString with IntRange.- Parameters:
- self- a GString
- range- an IntRange
- Returns:
- the String of characters corresponding to the provided range
- Since:
- 2.3.7
 
- 
getAtSupports the range subscript operator for CharSequence.- Parameters:
- self- a CharSequence
- range- a Range
- Returns:
- the subsequence CharSequence
- Since:
- 1.0
 
- 
getAtSupports the range subscript operator for GString.- Parameters:
- self- a GString
- range- a Range
- Returns:
- the String of characters corresponding to the provided range
- Since:
- 2.3.7
 
- 
getAtpublic static java.util.List getAt(java.util.regex.Matcher self, java.util.Collection indices)Selects a List of values from a Matcher using a Collection to identify the indices to be selected.- Parameters:
- self- a Matcher
- indices- a Collection of indices
- Returns:
- a String of the values at the given indices
- Since:
- 1.6.0
 
- 
getAtpublic static java.lang.Object getAt(java.util.regex.Matcher self, int index)Supports the subscript operator, e.g.matcher[index], for aMatcher.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] }- Parameters:
- self- a Matcher
- index- an index
- Returns:
- object a matched String if no groups matched, list of matched groups otherwise.
- Since:
- 1.0
 
- 
matchesPartiallypublic static boolean matchesPartially(java.util.regex.Matcher self)Given a matcher that matches a string against a pattern, returns true when the string matches the pattern or if a longer string, could match the pattern. For example: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()- Parameters:
- self- the Matcher
- Returns:
- true if more input to the String could make the matcher match the associated pattern, false otherwise.
- Since:
- 2.0.0
 
- 
getAtpublic static java.lang.String getAt(java.lang.String self, int index)Supports the subscript operator for String.- Parameters:
- self- a String
- index- the index of the Character to get
- Returns:
- the Character at the given index
- Since:
- 1.0
 
- 
getAtSupports the range subscript operator for String with IntRange.- Parameters:
- self- a String
- range- an IntRange
- Returns:
- the resulting String
- Since:
- 1.0
 
- 
getAtSupports the range subscript operator for String.- Parameters:
- self- a String
- range- a Range
- Returns:
- a substring corresponding to the Range
- Since:
- 1.0
 
- 
getCharspublic static char[] getChars(java.lang.CharSequence self)Converts the given CharSequence into an array of characters.- Parameters:
- self- a CharSequence
- Returns:
- an array of characters
- Since:
- 1.8.2
 
- 
getCountpublic static int getCount(java.util.regex.Matcher self)Finds the number of Strings matched to the given Matcher.- Parameters:
- self- a Matcher
- Returns:
- int the number of Strings matched to the given matcher.
- Since:
- 1.0
 
- 
hasGrouppublic static boolean hasGroup(java.util.regex.Matcher self)Checks whether a Matcher contains a group or not.- Parameters:
- self- a Matcher
- Returns:
- boolean  trueif matcher contains at least one group.
- Since:
- 1.0
 
- 
isAllWhitespacepublic static boolean isAllWhitespace(java.lang.CharSequence self)Returns true if a CharSequence only contains whitespace characters.- Parameters:
- self- The CharSequence to check the characters in
- Returns:
- true If all characters are whitespace characters
- Since:
- 1.8.2
 
- 
isBigDecimalpublic static boolean isBigDecimal(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a BigDecimal.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
 
- 
isBigIntegerpublic static boolean isBigInteger(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a BigInteger.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
 
- 
isCasepublic 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. This allows CharSequence values to be used in switch statements. For example:switch( str ) { case 'one' : // etc... }Note that this returnstruefor the case where both the 'switch' and 'case' operand isnull.- Parameters:
- caseValue- the case value
- switchValue- the switch value
- Returns:
- true if the switchValue's toString() equals the caseValue
- Since:
- 1.8.2
 
- 
isCasepublic static boolean isCase(java.util.regex.Pattern caseValue, java.lang.Object switchValue)'Case' implementation for thePatternclass, 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 arenull.- Parameters:
- caseValue- the case value
- switchValue- the switch value
- Returns:
- true if the switchValue is deemed to match the caseValue
- Since:
- 1.0
 
- 
isDoublepublic static boolean isDouble(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Double.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
 
- 
isFloatpublic static boolean isFloat(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Float.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
 
- 
isIntegerpublic static boolean isInteger(java.lang.CharSequence self)Determines if a CharSequence can be parsed as an Integer.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
 
- 
isLongpublic static boolean isLong(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Long.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
 
- 
isNumberpublic static boolean isNumber(java.lang.CharSequence self)Determines if a CharSequence can be parsed as a Number.- Parameters:
- self- a CharSequence
- Returns:
- true if the CharSequence can be parsed
- Since:
- 1.8.2
- See Also:
- isBigDecimal(CharSequence)
 
- 
iteratorpublic static java.util.Iterator iterator(java.util.regex.Matcher self)Returns anIteratorwhich traverses each match.- Parameters:
- self- a Matcher object
- Returns:
- an Iterator for a Matcher
- Since:
- 1.0
- See Also:
- Matcher.group()
 
- 
leftShiftpublic 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.- Parameters:
- self- a CharSequence
- value- an Object
- Returns:
- a StringBuilder built from this CharSequence
- Since:
- 1.8.2
 
- 
leftShiftpublic 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.- Parameters:
- self- a String
- value- an Object
- Returns:
- a StringBuffer built from this string
- Since:
- 1.0
 
- 
leftShiftpublic 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.- Parameters:
- self- a StringBuffer
- value- a value to append
- Returns:
- the StringBuffer on which this operation was invoked
- Since:
- 1.0
 
- 
leftShiftpublic 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.- Parameters:
- self- a StringBuilder
- value- an Object
- Returns:
- the original StringBuilder
- Since:
- 1.8.2
 
- 
matchespublic static boolean matches(java.lang.CharSequence self, java.util.regex.Pattern pattern)Determines if a CharSequence matches the given regular expression.- Parameters:
- self- the CharSequence that is to be matched
- pattern- the regex Pattern to which the string of interest is to be matched
- Returns:
- true if the CharSequence matches
- Since:
- 1.8.2
- See Also:
- String.matches(String)
 
- 
minuspublic static java.lang.String minus(java.lang.CharSequence self, java.lang.Object target)Removes a part of a CharSequence by replacing the first occurrence of target within self with empty string and returns the result.- Parameters:
- self- a CharSequence
- target- an object representing the part to remove
- Returns:
- a String containing the original minus the part to be removed
- Since:
- 1.8.2
 
- 
minuspublic static java.lang.String minus(java.lang.CharSequence self, java.util.regex.Pattern pattern)Removes a part of a CharSequence. This replaces the first occurrence of the pattern within self with empty string and returns the result.- Parameters:
- self- a String
- pattern- a Pattern representing the part to remove
- Returns:
- a String minus the part to be removed
- Since:
- 2.2.0
 
- 
multiplypublic static java.lang.String multiply(java.lang.CharSequence self, java.lang.Number factor)Repeats a CharSequence a certain number of times.- Parameters:
- self- a CharSequence to be repeated
- factor- the number of times the CharSequence should be repeated
- Returns:
- a String composed of a repetition
- Throws:
- java.lang.IllegalArgumentException- if the number of repetitions is < 0
- Since:
- 1.8.2
 
- 
nextpublic static java.lang.String next(java.lang.CharSequence self)Overloads the++operator for the class CharSequence. It increments the last character in the given CharSequence. If the last character in the CharSequence is Character.MAX_VALUE a Character.MIN_VALUE will be appended. The empty CharSequence is incremented to a string consisting of the character Character.MIN_VALUE.- Parameters:
- self- a CharSequence
- Returns:
- a value obtained by incrementing the toString() of the CharSequence
- Since:
- 1.8.2
 
- 
normalizepublic static java.lang.String normalize(java.lang.CharSequence self)Returns a String with linefeeds and carriage returns normalized to linefeeds.- Parameters:
- self- a CharSequence object
- Returns:
- the normalized toString() for the CharSequence
- Since:
- 1.8.2
 
- 
padLeftpublic static java.lang.String padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars)Pads a CharSequence to a minimum length specified bynumberOfCharsby adding the space character to the left as many times as needed. If the String is already the same size or bigger than the targetnumberOfChars, then the original String is returned. An example:println 'Numbers:' [1, 10, 100, 1000].each{ println it.toString().padLeft(5) }will produce output like:Numbers: 1 10 100 1000- Parameters:
- self- a CharSequence object
- numberOfChars- the total minimum number of characters of the resulting CharSequence
- Returns:
- the CharSequence padded to the left as a String
- Since:
- 1.8.2
- See Also:
- padLeft(CharSequence,Number,CharSequence)
 
- 
padLeftpublic static java.lang.String padLeft(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)Pads a CharSequence to a minimum length specified bynumberOfChars, adding the supplied padding CharSequence as many times as needed to the left. If the CharSequence is already the same size or bigger than the targetnumberOfChars, then the toString() of the original CharSequence is returned. An example: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 - Parameters:
- self- a CharSequence object
- numberOfChars- the total minimum number of characters of the resulting CharSequence
- padding- the characters used for padding
- Returns:
- the CharSequence padded to the left as a String
- Since:
- 1.8.2
 
- 
padRightpublic static java.lang.String padRight(java.lang.CharSequence self, java.lang.Number numberOfChars)Pads a CharSequence to a minimum length specified bynumberOfCharsby adding the space character to the right as many times as needed. If the CharSequence is already the same size or bigger than the targetnumberOfChars, then the toString() of the original CharSequence is returned. An example:['A', 'BB', 'CCC', 'DDDD'].each{ println it.padRight(5) + it.size() }will produce output like:A 1 BB 2 CCC 3 DDDD 4 - Parameters:
- self- a CharSequence object
- numberOfChars- the total minimum number of characters of the resulting string
- Returns:
- the CharSequence padded to the right as a String
- Since:
- 1.8.2
 
- 
padRightpublic static java.lang.String padRight(java.lang.CharSequence self, java.lang.Number numberOfChars, java.lang.CharSequence padding)Pads a CharSequence to a minimum length specified bynumberOfChars, adding the supplied padding CharSequence as many times as needed to the right. If the CharSequence is already the same size or bigger than the targetnumberOfChars, then the toString() of the original CharSequence is returned. An example:['A', 'BB', 'CCC', 'DDDD'].each{ println it.padRight(5, '#') + it.size() }will produce output like:A####1 BB###2 CCC##3 DDDD#4 - Parameters:
- self- a CharSequence object
- numberOfChars- the total minimum number of characters of the resulting CharSequence
- padding- the characters used for padding
- Returns:
- the CharSequence padded to the right as a String
- Since:
- 1.8.2
 
- 
pluspublic static java.lang.String plus(java.lang.CharSequence left, java.lang.Object right)Appends the String representation of the given operand to this CharSequence.- Parameters:
- left- a CharSequence
- right- any Object
- Returns:
- the original toString() of the CharSequence with the object appended
- Since:
- 1.8.2
 
- 
pluspublic static java.lang.String plus(java.lang.Number left, java.lang.String right)Appends a String to the string representation of this number.- Parameters:
- left- a Number
- right- a String
- Returns:
- a String
- Since:
- 1.0
 
- 
pluspublic static java.lang.String plus(java.lang.String left, java.lang.CharSequence right)Appends the String representation of the given operand to this string.- Parameters:
- left- a String
- right- any CharSequence
- Returns:
- the new string with the object appended
- Since:
- 2.2
 
- 
pluspublic static java.lang.String plus(java.lang.StringBuffer left, java.lang.String right)Appends a String to this StringBuffer.- Parameters:
- left- a StringBuffer
- right- a String
- Returns:
- a String
- Since:
- 1.0
 
- 
previouspublic static java.lang.String previous(java.lang.CharSequence self)Overloads the--operator for the class CharSequence. It decrements the last character in the given CharSequence. If the last character in the CharSequence is Character.MIN_VALUE it will be deleted. The empty CharSequence can't be decremented.- Parameters:
- self- a CharSequence
- Returns:
- a String with a decremented character at the end
- Since:
- 1.8.2
 
- 
putAtSupports the range subscript operator for StringBuffer.- Parameters:
- self- a StringBuffer
- range- a Range
- value- the object that's toString() will be inserted
- Since:
- 1.0
 
- 
putAtSupports the range subscript operator for StringBuffer. Index values are treated as characters within the buffer.- Parameters:
- self- a StringBuffer
- range- a Range
- value- the object that's toString() will be inserted
- Since:
- 1.0
 
- 
readLinespublic static java.util.List<java.lang.String> readLines(java.lang.CharSequence self)Returns the lines of a CharSequence as a List of String.- Parameters:
- self- a CharSequence object
- Returns:
- a list of lines
- Since:
- 1.8.2
 
- 
replaceAllpublic 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.assert "foo".replaceAll('o', 'X') == 'fXX'- Parameters:
- self- a CharSequence
- regex- the capturing regex
- replacement- the string to be substituted for each match
- Returns:
- the toString() of the CharSequence with content replaced
- Throws:
- java.util.regex.PatternSyntaxException- if the regular expression's syntax is invalid
- Since:
- 1.8.2
- See Also:
- String.replaceAll(String,String)
 
- 
replaceAllpublic 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.Examples: assert "hello world".replaceAll("(o)") { it[0].toUpperCase() } == "hellO wOrld" assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] itNote 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.->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 group- Parameters:
- self- a CharSequence
- regex- the capturing regex
- closure- the closure to apply on each captured group
- Returns:
- the toString() of the CharSequence with content replaced
- Throws:
- java.util.regex.PatternSyntaxException- if the regular expression's syntax is invalid
- Since:
- 1.8.2
- See Also:
- replaceAll(CharSequence,Pattern,Closure)
 
- 
replaceAllpublic 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.Note that backslashes ( \) and dollar signs ($) in the replacement string may cause the results to be different from if it were being treated as a literal replacement string; seeMatcher.replaceAll(java.lang.String). UseMatcher.quoteReplacement(java.lang.String)to suppress the special meaning of these characters, if desired.assert "foo".replaceAll(~'o', 'X') == 'fXX' - Parameters:
- self- the CharSequence that is to be matched
- pattern- the regex Pattern to which the CharSequence of interest is to be matched
- replacement- the CharSequence to be substituted for the first match
- Returns:
- the toString() of the CharSequence with content replaced
- Since:
- 1.8.2
 
- 
replaceAllpublic 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.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[] itNote 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.->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 group- Parameters:
- self- a CharSequence
- pattern- the capturing regex Pattern
- closure- the closure to apply on each captured group
- Returns:
- the toString() of the CharSequence with replaced content
- Since:
- 1.8.2
- See Also:
- Matcher.quoteReplacement(String)
 
- 
replaceFirstpublic 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.- Parameters:
- self- a CharSequence
- regex- the capturing regex
- replacement- the CharSequence to be substituted for each match
- Throws:
- java.util.regex.PatternSyntaxException- if the regular expression's syntax is invalid
- Since:
- 1.8.2
- See Also:
- String.replaceFirst(String,String)
 
- 
replaceFirstpublic 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.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'- Parameters:
- self- a CharSequence
- regex- the capturing regex
- closure- the closure to apply on the first captured group
- Throws:
- java.util.regex.PatternSyntaxException- if the regular expression's syntax is invalid
- Since:
- 1.8.2
 
- 
replaceFirstpublic 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.Note that backslashes ( \) and dollar signs ($) in the replacement string may cause the results to be different from if it were being treated as a literal replacement string; seeMatcher.replaceFirst(java.lang.String). UseMatcher.quoteReplacement(java.lang.String)to suppress the special meaning of these characters, if desired.assert "foo".replaceFirst('o', 'X') == 'fXo'- Parameters:
- self- the CharSequence that is to be matched
- pattern- the regex Pattern to which the CharSequence of interest is to be matched
- replacement- the CharSequence to be substituted for the first match
- Since:
- 1.8.2
 
- 
replaceFirstpublic 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.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() }- Parameters:
- self- a CharSequence
- pattern- the capturing regex Pattern
- closure- the closure to apply on the first captured group
- Since:
- 1.8.2
 
- 
replacepublic static java.lang.String replace(java.lang.CharSequence self, java.util.Map<java.lang.CharSequence,java.lang.CharSequence> replacements)Replaces all occurrences of replacement CharSequences (supplied via a map) within a provided CharSequence.assert 'foobar'.replace(f:'b', foo:'bar') == 'boobar' assert 'foobar'.replace(foo:'bar', f:'b') == 'barbar' def replacements = [foo:'bar', f:'b', b: 'f', bar:'boo'] assert 'foobar'.replace(replacements) == 'barfar' - Parameters:
- self- a CharSequence
- replacements- a map of before (key) and after (value) pairs processed in the natural order of the map
- Returns:
- a String formed from the provided CharSequence after performing all of the replacements
- Since:
- 2.5.0
 
- 
replacepublic static java.lang.String replace(java.lang.CharSequence self, int capacity, java.util.Map<java.lang.CharSequence,java.lang.CharSequence> replacements)Replaces all occurrences of replacement CharSequences (supplied via a map) within a provided CharSequence with control over the internally created StringBuilder's capacity. This method uses a StringBuilder internally. Java auto-expands a StringBuilder's capacity if needed. In rare circumstances, the overhead involved with repeatedly expanding the StringBuilder may become significant. If you have measured the performance of your application and found this to be a significant bottleneck, use this variant to have complete control over the internally created StringBuilder's capacity.assert 'foobar'.replace(9, [r:'rbaz']) == 'foobarbaz' assert 'foobar'.replace(1, [fooba:'']) == 'r' - Parameters:
- self- a CharSequence
- capacity- an optimization parameter, set to size after replacements or a little larger to avoid resizing overheads
- replacements- a map of before (key) and after (value) pairs processed in the natural order of the map
- Returns:
- a String formed from the provided CharSequence after performing all of the replacements
- Since:
- 2.5.0
 
- 
reversepublic static java.lang.String reverse(java.lang.CharSequence self)Creates a String which is the reverse (backwards) of this CharSequence- Parameters:
- self- a CharSequence
- Returns:
- a new String with all the characters reversed.
- Since:
- 1.8.2
 
- 
setIndexpublic static void setIndex(java.util.regex.Matcher self, int index)Sets the position of the given Matcher to the given index.- Parameters:
- self- a Matcher
- index- the index number
- Since:
- 1.0
 
- 
sizepublic static int size(java.lang.CharSequence self)Provides the standard Groovysize()method forCharSequence.- Parameters:
- self- a CharSequence
- Returns:
- the length of the CharSequence
- Since:
- 1.8.2
 
- 
sizepublic static long size(java.util.regex.Matcher self)Provides the standard Groovysize()method forMatcher.- Parameters:
- self- a matcher object
- Returns:
- the matcher's size (count)
- Since:
- 1.5.0
 
- 
size@Deprecated public static int size(java.lang.String self)Deprecated.Provides the standard Groovysize()method forString.- Parameters:
- self- a String
- Returns:
- the length of the String
- Since:
- 1.0
- See Also:
- size(CharSequence)
 
- 
size@Deprecated public static int size(java.lang.StringBuffer self)Deprecated.Provides the standard Groovysize()method forStringBuffer.- Parameters:
- self- a StringBuffer
- Returns:
- the length of the StringBuffer
- Since:
- 1.0
- See Also:
- size(CharSequence)
 
- 
isAtLeastpublic static java.lang.Boolean isAtLeast(java.lang.String left, java.lang.String right)Compares a String representing a number to another. A fluent API style alias forcompareToonBigDecimal.- Parameters:
- left- a String representing a number
- right- a String representing a number
- Returns:
- true if the value represented by left is equal to or bigger than the value represented by right
- Since:
- 3.0.1
 
- 
splitpublic static java.lang.String[] split(java.lang.CharSequence self)Splits a CharSequence (with whitespace as delimiter). Similar to tokenize, but returns an Array of String instead of a List.- Parameters:
- self- the CharSequence to split
- Returns:
- String[] result of split
- Since:
- 1.8.2
 
- 
splitEachLinepublic static <T> T splitEachLine(java.lang.CharSequence self, java.lang.CharSequence regex, Closure<T> closure) throws java.io.IOExceptionIterates through the given CharSequence line by line, splitting each line using the given regex delimiter. The list of tokens for each line is then passed to the given closure.- Parameters:
- self- a CharSequence
- regex- the delimiting regular expression
- closure- a closure
- Returns:
- the last value returned by the closure
- Throws:
- java.io.IOException- if an error occurs
- java.util.regex.PatternSyntaxException- if the regular expression's syntax is invalid
- Since:
- 1.8.2
- See Also:
- splitEachLine(CharSequence,Pattern,Closure)
 
- 
splitEachLinepublic 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. The list of tokens for each line is then passed to the given closure.- Parameters:
- self- a CharSequence
- pattern- the regular expression Pattern for the delimiter
- closure- a closure
- Returns:
- the last value returned by the closure
- Since:
- 1.8.2
 
- 
stripIndentpublic static java.lang.String stripIndent(java.lang.CharSequence self)Strips leading spaces from every line in a CharSequence. The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.assert ' A\n B\nC' == ' A\n B\n C'.stripIndent() - Parameters:
- self- a CharSequence to strip the leading spaces from
- Returns:
- the stripped toString()of the CharSequence
- Since:
- 1.8.2
 
- 
stripIndent@Incubating public static java.lang.String stripIndent(java.lang.CharSequence self, boolean forceGroovyBehavior)Same logic asstripIndent(CharSequence)ifforceGroovyBehavioristrue, otherwise Java 13'sstripIndentwill be invoked.- Parameters:
- self- The CharSequence to strip the leading spaces from
- forceGroovyBehavior- force groovy behavior to avoid conflicts with Java13's stripIndent
- Since:
- 3.0.0
 
- 
stripIndentpublic static java.lang.String stripIndent(java.lang.CharSequence self, int numChars)StripsnumCharsleading characters from every line in a CharSequence.assert 'DEF\n456' == '''ABCDEF\n123456'''.stripIndent(3) - Parameters:
- self- The CharSequence to strip the characters from
- numChars- The number of characters to strip
- Returns:
- the stripped String
- Since:
- 1.8.2
 
- 
stripMarginpublic static java.lang.String stripMargin(java.lang.CharSequence self)Strips leading whitespace/control characters followed by '|' from every line in a CharSequence.assert 'ABC\n123\n456' == '''ABC |123 |456'''.stripMargin()- Parameters:
- self- The CharSequence to strip the margin from
- Returns:
- the stripped String
- Since:
- 1.8.2
- See Also:
- stripMargin(CharSequence,char)
 
- 
stripMarginpublic static java.lang.String stripMargin(java.lang.CharSequence self, char marginChar)Strips leading whitespace/control characters followed bymarginCharfrom every line in a CharSequence.assert 'ABC\n123\n456' == '''ABC *123 *456'''.stripMargin('*')- Parameters:
- self- The CharSequence to strip the margin from
- marginChar- Any character that serves as margin delimiter
- Returns:
- the stripped String
- Since:
- 1.8.2
 
- 
stripMarginpublic static java.lang.String stripMargin(java.lang.CharSequence self, java.lang.CharSequence marginChar)Strips leading whitespace/control characters followed bymarginCharfrom every line in a CharSequence.- Parameters:
- self- The CharSequence to strip the margin from
- marginChar- Any character that serves as margin delimiter
- Returns:
- the stripped CharSequence
- Since:
- 1.8.2
 
- 
takepublic static java.lang.CharSequence take(java.lang.CharSequence self, int num)Returns the firstnumelements from this CharSequence.def text = "Groovy" assert text.take( 0 ) == '' assert text.take( 2 ) == 'Gr' assert text.take( 7 ) == 'Groovy' - Parameters:
- self- the original CharSequence
- num- the number of chars to take from this CharSequence
- Returns:
- a CharSequence consisting of the first numchars, or else the whole CharSequence if it has less thannumelements.
- Since:
- 1.8.1
 
- 
takeA GString variant of the equivalent CharSequence method.- Parameters:
- self- the original GString
- num- the number of chars to take from this GString
- Returns:
- a String consisting of the first numchars, or else the whole GString if it has less thannumelements.
- Since:
- 2.3.7
 
- 
takepublic static java.lang.String take(java.lang.String self, int num)A String variant of the equivalent CharSequence method.- Parameters:
- self- the original String
- num- the number of chars to take from this String
- Returns:
- a String consisting of the first numchars, or else the whole String if it has less thannumelements.
- Since:
- 2.5.5
 
- 
takeWhileReturns the longest prefix of this CharSequence where each element passed to the given closure evaluates to true.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'- Parameters:
- self- the original CharSequence
- condition- the closure that must evaluate to true to continue taking elements
- Returns:
- a prefix of elements in the CharSequence where each element passed to the given closure evaluates to true
- Since:
- 2.0.0
 
- 
takeWhile$$bridge@Deprecated public static java.lang.CharSequence takeWhile$$bridge(java.lang.CharSequence self, Closure condition)Deprecated.
- 
takeWhileA GString variant of the equivalent GString method.- Parameters:
- self- the original GString
- condition- the closure that must evaluate to true to continue taking elements
- Returns:
- a prefix of elements in the GString where each element passed to the given closure evaluates to true
- Since:
- 2.3.7
 
- 
toBigDecimalpublic static java.math.BigDecimal toBigDecimal(java.lang.CharSequence self)Parses a CharSequence into a BigDecimal- Parameters:
- self- a CharSequence
- Returns:
- a BigDecimal
- Since:
- 1.8.2
 
- 
toBigIntegerpublic static java.math.BigInteger toBigInteger(java.lang.CharSequence self)Parses a CharSequence into a BigInteger- Parameters:
- self- a CharSequence
- Returns:
- a BigInteger
- Since:
- 1.8.2
 
- 
toBooleanpublic static java.lang.Boolean toBoolean(java.lang.String self)Converts the given string into a Boolean object. If the trimmed string is "true", "y" or "1" (ignoring case) then the result is true otherwise it is false.- Parameters:
- self- a String
- Returns:
- The Boolean value
- Since:
- 1.0
 
- 
toCharacterpublic static java.lang.Character toCharacter(java.lang.String self)Converts the given string into a Character object using the first character in the string.- Parameters:
- self- a String
- Returns:
- the first Character
- Since:
- 1.0
 
- 
toDoublepublic static java.lang.Double toDouble(java.lang.CharSequence self)Parses a CharSequence into a Double.- Parameters:
- self- a CharSequence
- Returns:
- a Double
- Since:
- 1.8.2
 
- 
toFloatpublic static java.lang.Float toFloat(java.lang.CharSequence self)Parses a CharSequence into a Float.- Parameters:
- self- a CharSequence
- Returns:
- a Float
- Since:
- 1.8.2
 
- 
toIntegerpublic static java.lang.Integer toInteger(java.lang.CharSequence self)Parses a CharSequence into an Integer.- Parameters:
- self- a CharSequence
- Returns:
- an Integer
- Since:
- 1.8.2
 
- 
tokenizepublic static java.util.List<java.lang.String> tokenize(java.lang.CharSequence self)Tokenizes a CharSequence (with a whitespace as the delimiter).- Parameters:
- self- a CharSequence
- Returns:
- a List of tokens
- Since:
- 1.8.2
- See Also:
- StringTokenizer(String)
 
- 
tokenizepublic static java.util.List<java.lang.String> tokenize(java.lang.CharSequence self, java.lang.Character delimiter)Tokenizes a CharSequence based on the given character delimiter.For example: char pathSep = ':' assert "/tmp:/usr".tokenize(pathSep) == ["/tmp", "/usr"] - Parameters:
- self- a CharSequence
- delimiter- the delimiter
- Returns:
- a List of tokens
- Since:
- 1.8.2
- See Also:
- StringTokenizer(String,String)
 
- 
tokenizepublic static java.util.List<java.lang.String> tokenize(java.lang.CharSequence self, java.lang.CharSequence delimiters)Tokenizes a CharSequence based on the given CharSequence. Each character in the CharSequence is a separate delimiter.- Parameters:
- self- a CharSequence
- delimiters- the delimiters
- Returns:
- a List of tokens
- Since:
- 1.8.2
- See Also:
- StringTokenizer(String,String)
 
- 
toListpublic static java.util.List<java.lang.String> toList(java.lang.CharSequence self)Converts the given CharSequence into a List of Strings of one character.- Parameters:
- self- a CharSequence
- Returns:
- a List of characters (a 1-character String)
- Since:
- 1.8.2
 
- 
toLongpublic static java.lang.Long toLong(java.lang.CharSequence self)Parses a CharSequence into a Long- Parameters:
- self- a CharSequence
- Returns:
- a Long
- Since:
- 1.8.2
 
- 
toSetpublic 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.- Parameters:
- self- a CharSequence
- Returns:
- a Set of unique characters (each a 1-character String)
- Since:
- 1.8.2
 
- 
toShortpublic static java.lang.Short toShort(java.lang.CharSequence self)Parses a CharSequence into a Short.- Parameters:
- self- a CharSequence
- Returns:
- a Short
- Since:
- 1.8.2
 
- 
trpublic static java.lang.String tr(java.lang.CharSequence self, java.lang.CharSequence sourceSet, java.lang.CharSequence replacementSet) throws java.lang.ClassNotFoundExceptionTranslates a CharSequence by replacing characters from the sourceSet with characters from replacementSet. If the first character from sourceSet appears in the CharSequence, it will be replaced with the first character from replacementSet. If the second character from sourceSet appears in the CharSequence, it will be replaced with the second character from replacementSet. and so on for all provided replacement characters.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.- Parameters:
- self- the CharSequence that is to be translated
- sourceSet- the set of characters to translate from
- replacementSet- the set of replacement characters
- Returns:
- The resulting translated String
- Throws:
- java.lang.ClassNotFoundException
- Since:
- 1.8.2
- See Also:
- StringUtil.tr(String,String,String)
 
- 
unexpandpublic static java.lang.String unexpand(java.lang.CharSequence self)Replaces sequences of whitespaces with tabs using tabStops of size 8.- Parameters:
- self- A CharSequence to unexpand
- Returns:
- an unexpanded String
- Since:
- 1.8.2
 
- 
unexpandpublic static java.lang.String unexpand(java.lang.CharSequence self, int tabStop)Replaces sequences of whitespaces with tabs.- Parameters:
- self- A CharSequence to unexpand
- tabStop- The number of spaces a tab represents
- Returns:
- an unexpanded String
- Since:
- 1.8.2
 
- 
unexpandLinepublic static java.lang.String unexpandLine(java.lang.CharSequence self, int tabStop)Replaces sequences of whitespaces with tabs within a line.- Parameters:
- self- A line to unexpand
- tabStop- The number of spaces a tab represents
- Returns:
- an unexpanded String
- Since:
- 1.8.2
 
- 
startsWithAnypublic static boolean startsWithAny(java.lang.CharSequence self, java.lang.CharSequence... prefixes)Tests if this CharSequence starts with any specified prefixes.- Parameters:
- prefixes- the prefixes.
- Returns:
- trueif this CharSequence starts with any specified prefixes.
- Since:
- 2.4.14
 
- 
endsWithAnypublic static boolean endsWithAny(java.lang.CharSequence self, java.lang.CharSequence... suffixes)Tests if this CharSequence ends with any specified suffixes.- Parameters:
- suffixes- the suffixes.
- Returns:
- trueif this CharSequence ends with any specified suffixes
- Since:
- 2.4.14
 
- 
isBlankpublic static boolean isBlank(java.lang.CharSequence self)Tests if this CharSequence is blank.- Returns:
- trueif this CharSequence is blank
- Since:
- 2.5.0
- See Also:
- isAllWhitespace(CharSequence)
 
- 
takeRightpublic static java.lang.CharSequence takeRight(java.lang.CharSequence self, int num)Returns the lastnumelements from this CharSequence.def text = "Groovy" assert text.takeRight( 0 ) == '' assert text.takeRight( 2 ) == 'vy' assert text.takeRight( 7 ) == 'Groovy' - Parameters:
- self- the original CharSequence
- num- the number of chars to take from this CharSequence from the right
- Returns:
- a CharSequence consisting of the last numchars, or else the whole CharSequence if it has less thannumelements.
- Since:
- 3.0.0
 
- 
takeRightpublic static java.lang.String takeRight(java.lang.String self, int num)A GString variant of the equivalent CharSequence methodtakeRight(CharSequence,int).- Parameters:
- self- the original CharSequence
- num- the number of chars to take from this CharSequence from the right
- Returns:
- a String consisting of the last numchars, or else the whole CharSequence if it has less thannumelements.
- Since:
- 3.0.0
 
- 
takeRightA String variant of the equivalent CharSequence methodtakeRight(CharSequence,int).- Parameters:
- self- the original GString
- num- the number of chars to take from this GString from the right
- Returns:
- a String consisting of the last numchars, or else the whole GString if it has less thannumelements.
- Since:
- 3.0.0
 
- 
takeAfterpublic static java.lang.CharSequence takeAfter(java.lang.CharSequence self, java.lang.CharSequence searchString)Returns theCharSequencethat exists after the first occurrence of the givensearchStringin this CharSequence.def text = "Groovy development. Groovy team" assert text.takeAfter( 'Groovy' ) == ' development. Groovy team' assert text.takeAfter( 'team' ) == '' assert text.takeAfter( '' ) == '' assert text.takeAfter( 'Unavailable text' ) == '' assert text.takeAfter( null ) == '' - Parameters:
- self- the original CharSequence
- searchString- CharSequence that is searched in this CharSequence
- Returns:
- CharSequence that is after the given searchString and empty string if it does not exist
- Since:
- 3.0.0
 
- 
takeAfterpublic static java.lang.String takeAfter(java.lang.String self, java.lang.CharSequence searchString)A String variant of the equivalent CharSequence methodtakeAfter(CharSequence,CharSequence).- Parameters:
- self- the original CharSequence
- searchString- String that is searched in this CharSequence
- Returns:
- String that is after the given searchString and empty string if it does not exist
- Since:
- 3.0.0
 
- 
takeAfterA GString variant of the equivalent CharSequence methodtakeAfter(CharSequence,CharSequence).- Parameters:
- self- the original CharSequence
- searchString- CharSequence that is searched in this CharSequence
- Returns:
- String that is after the given searchString and empty string if it does not exist
- Since:
- 3.0.0
 
- 
takeBeforepublic static java.lang.CharSequence takeBefore(java.lang.CharSequence self, java.lang.CharSequence searchString)Returns theCharSequencethat exists before the first occurrence of the givensearchStringin this CharSequence.def text = "Groovy development. Groovy team" assert text.takeBefore( ' Groovy ' ) == 'Groovy development.' assert text.takeBefore( ' ' ) == 'Groovy' assert text.takeBefore( 'Unavailable text' ) == '' assert text.takeBefore( null ) == '' - Parameters:
- self- the original CharSequence
- searchString- CharSequence that is searched in this CharSequence
- Returns:
- CharSequence that is before the given searchString
- Since:
- 3.0.0
 
- 
takeBeforeA GString variant of the equivalent CharSequence methodtakeBefore(CharSequence,CharSequence).- Parameters:
- self- the original CharSequence
- searchString- CharSequence that is searched in this CharSequence
- Returns:
- String that is before the given searchString
- Since:
- 3.0.0
 
- 
takeBeforepublic static java.lang.String takeBefore(java.lang.String self, java.lang.String searchString)A String variant of the equivalent CharSequence methodtakeBefore(CharSequence,CharSequence).- Parameters:
- self- the original CharSequence
- searchString- CharSequence that is searched in this CharSequence
- Returns:
- String that is before the given searchString
- Since:
- 3.0.0
 
- 
dropRightpublic static java.lang.CharSequence dropRight(java.lang.CharSequence self, int num)Returns new CharSequence after removing the rightnumchars. Returns empty String if thenumis greater than the length of the CharSequence.def text = "groovy" assert text.dropRight( 3 ) == 'gro' assert text.dropRight( 6 ) == '' assert text.dropRight( 0 ) == 'groovy' assert text.dropRight( -1 ) == 'groovy' assert text.dropRight( 10 ) == '' - Parameters:
- self- the original CharSequence
- num- number of characters
- Returns:
- CharSequence after removing the right numchars and empty of thenumis greater than the length of the CharSequence
- Since:
- 3.0.0
 
- 
dropRightpublic static java.lang.String dropRight(java.lang.String self, int num)A String variant of the equivalent CharSequence methoddropRight(CharSequence,int).- Parameters:
- self- the original CharSequence
- num- number of characters
- Returns:
- String after removing the right numchars and empty of thenumis greater than the length of the CharSequence
- Since:
- 3.0.0
 
- 
dropRightA GString variant of the equivalent CharSequence methoddropRight(CharSequence,int).- Parameters:
- self- the original CharSequence
- num- number of characters
- Returns:
- String after removing the right numchars and empty of thenumis greater than the length of the CharSequence
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.CharSequence takeBetween(java.lang.CharSequence self, java.lang.CharSequence from, java.lang.CharSequence to)Returns the CharSequence that is in between the first occurrence of the givenfromandtoCharSequences and empty if the unavailable inputs are given.def text = "Groovy" assert text.takeBetween( 'r', 'v' ) == 'oo' assert text.takeBetween( 'r', 'z' ) == '' assert text.takeBetween( 'a', 'r' ) == '' - Parameters:
- self- the original CharSequence
- from- beginning of search
- to- end of search
- Returns:
- the CharSequence that is in between the given two CharSequences and empty if the unavailable inputs are given
- Since:
- 3.0.0
- See Also:
- takeBetween(CharSequence,CharSequence,CharSequence,int)
 
- 
takeBetweenpublic static java.lang.String takeBetween(java.lang.String self, java.lang.CharSequence from, java.lang.CharSequence to)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence).- Parameters:
- self- the original CharSequence
- from- beginning of search
- to- end of search
- Returns:
- String that is in between the given two CharSequences and empty if the unavailable inputs are given
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.String takeBetween(GString self, java.lang.CharSequence from, java.lang.CharSequence to)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence).- Parameters:
- self- the original CharSequence
- from- beginning of search
- to- end of search
- Returns:
- String that is in between the given two CharSequences and empty if the unavailable inputs are given
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.CharSequence takeBetween(java.lang.CharSequence self, java.lang.CharSequence enclosure)Takes the characters between the first occurrence of the two subsequentenclosurestrings.def text = "name = 'some name'" assert text.takeBetween( "'" ) == 'some name' assert text.takeBetween( 'z' ) == '' - Parameters:
- self- Original CharSequence
- enclosure- Enclosure CharSequence
- Returns:
- CharSequence between the 2 subsequent enclosurestrings
- Since:
- 3.0.0
- See Also:
- takeBetween(CharSequence,CharSequence,int)
 
- 
takeBetweenpublic static java.lang.String takeBetween(java.lang.String self, java.lang.CharSequence enclosure)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence).- Parameters:
- self- Original String
- enclosure- Enclosure CharSequence
- Returns:
- String between the 2 subsequent enclosurestrings
- Since:
- 3.0.0
 
- 
takeBetweenA GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence).- Parameters:
- self- Original GString
- enclosure- Enclosure CharSequence
- Returns:
- String between the 2 subsequent enclosurestrings
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.CharSequence takeBetween(java.lang.CharSequence self, java.lang.CharSequence from, java.lang.CharSequence to, int occurrence)Returns the CharSequence that is in between the given the nth (specified by occurrence) pair offromandtoCharSequences and empty if the unavailable inputs are given.def text = "t1=10 ms, t2=100 ms" assert text.takeBetween( '=', ' ', 0 ) == '10' assert text.takeBetween( '=', ' ', 1 ) == '100' assert text.takeBetween( 't1', 'z' ) == '' - Parameters:
- self- the original CharSequence
- from- beginning of search
- to- end of search
- occurrence- nth occurrence that is to be returned. 0 represents first one
- Returns:
- the CharSequence that is in between the given the nth (specified by occurrence) pair of
 fromandtoCharSequences and empty if the unavailable inputs are given.
- Since:
- 3.0.0
- See Also:
- takeBetween(CharSequence,CharSequence,CharSequence)
 
- 
takeBetweenpublic static java.lang.String takeBetween(java.lang.String self, java.lang.CharSequence from, java.lang.CharSequence to, int occurrence)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence,int).- Parameters:
- self- the original String
- from- beginning of search
- to- end of search
- occurrence- nth occurrence that is to be returned. 0 represents first one
- Returns:
- the String that is in between the given nth (specified by occurrence) pair of
 fromandtoCharSequences and empty if the unavailable inputs are given.
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.String takeBetween(GString self, java.lang.CharSequence from, java.lang.CharSequence to, int occurrence)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,CharSequence,int).- Parameters:
- self- the original GString
- from- beginning of search
- to- end of search
- occurrence- nth occurrence that is to be returned. 0 represents first one
- Returns:
- the String that is in between the given nth (specified by occurrence) pair of
 fromandtoCharSequences and empty if the unavailable inputs are given.
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.CharSequence takeBetween(java.lang.CharSequence self, java.lang.CharSequence enclosure, int occurrence)Takes the characters between nth (specified by occurrence) pair ofenclosurestrings.def text = "t1='10' ms, t2='100' ms" assert text.takeBetween( "'", 0 ) == '10' assert text.takeBetween( "'", 1 ) == '100' assert text.takeBetween( "'", 2 ) == '' - Parameters:
- self- Original CharSequence
- enclosure- Enclosure CharSequence
- occurrence- nth occurrence being returned
- Returns:
- CharSequence between the nth occurrence of pair of enclosurestrings
- Since:
- 3.0.0
- See Also:
- takeBetween(CharSequence,CharSequence,int)
 
- 
takeBetweenpublic static java.lang.String takeBetween(java.lang.String self, java.lang.CharSequence enclosure, int occurrence)A String variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,int).- Parameters:
- self- Original String
- enclosure- Enclosure CharSequence
- occurrence- nth occurrence being returned
- Returns:
- String between the nth occurrence of pair of enclosurestrings
- Since:
- 3.0.0
 
- 
takeBetweenpublic static java.lang.String takeBetween(GString self, java.lang.CharSequence enclosure, int occurrence)A GString variant of the equivalent CharSequence methodtakeBetween(CharSequence,CharSequence,int).- Parameters:
- self- Original GString
- enclosure- Enclosure CharSequence
- occurrence- nth occurrence being returned
- Returns:
- String between the nth occurrence of pair of enclosurestrings
- Since:
- 3.0.0
 
- 
startsWithIgnoreCasepublic static boolean startsWithIgnoreCase(java.lang.CharSequence self, java.lang.CharSequence searchString)Checks whether this CharSequence starts with thesearchStringignoring the case considerations.- Parameters:
- self- the original CharSequence
- searchString- CharSequence being checked against this
- Returns:
- trueif the character sequence represented by the argument is a prefix of this CharSequence ignoring the case considerations.- falseotherwise. Returns false if the argument is null
- Since:
- 3.0.0
 
- 
endsWithIgnoreCasepublic static boolean endsWithIgnoreCase(java.lang.CharSequence self, java.lang.CharSequence searchString)Checks whether this CharSequence ends with thesearchStringignoring the case considerations.- Parameters:
- self- the original CharSequence
- searchString- CharSequence bring checked against this
- Returns:
- trueif the character sequence represented by the argument is a suffix of this CharSequence ignoring the case considerations.- falseotherwise. Returns false if the argument is null
- Since:
- 3.0.0
 
- 
containsIgnoreCasepublic static boolean containsIgnoreCase(java.lang.CharSequence self, java.lang.CharSequence searchString)Checks whether this CharSequence contains thesearchStringignoring the caseConsiderations.- Parameters:
- self- the original CharSequence
- searchString- CharSequence being checked against this
- Returns:
- trueif the character sequence represented by the argument exists in this CharSequence ignoring the case considerations.- falseotherwise. Returns false if the argument is null
- Since:
- 3.0.0
 
 
-