Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK

## java.lang
Class CharSequence

Method Summary
`boolean` | `asBoolean()` Coerce a string (an instance of CharSequence) to a boolean value.
`Object` | `asType(Class c)` Provides a method to perform custom 'dynamic' type conversion to the given class using the `as` operator.
`Pattern` | `bitwiseNegate()` Turns a CharSequence into a regular expression Pattern
`CharSequence` | `capitalize()` Convenience method to capitalize the first letter of a CharSequence.
`CharSequence` | `center(Number numberOfChars)` Pad a CharSequence to a minimum length specified by `numberOfChars` by adding the space character around it as many times as needed so that it remains centered.
`CharSequence` | `center(Number numberOfChars, CharSequence padding)` Pad a CharSequence to a minimum length specified by `numberOfChars`, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.
`boolean` | `contains(CharSequence text)` Provide an implementation of contains() like Collection#contains to make CharSequences more polymorphic.
`int` | `count(CharSequence text)` Count the number of occurrences of a sub CharSequence.
`CharSequence` | `denormalize()` Return a CharSequence with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.
`CharSequence` | `drop(int num)` Drops the given number of chars from the head of this CharSequence if they are available.
`CharSequence` | `dropWhile(Closure condition)` Create a suffix of the given CharSequence by dropping as many characters as possible from the front of the original CharSequence such that calling the given closure condition evaluates to true when passed each of the dropped characters.
`Object` | `eachLine(Closure closure)` Iterates through this CharSequence line by line.
`Object` | `eachLine(int firstLine, Closure closure)` Iterates through this CharSequence line by line.
`String` | `eachMatch(CharSequence regex, Closure closure)` Process each regex group matched substring of the given CharSequence.
`String` | `eachMatch(Pattern pattern, Closure closure)` Process each regex group matched substring of the given pattern.
`CharSequence` | `expand()` Expands all tabs into spaces with tabStops of size 8.
`CharSequence` | `expand(int tabStop)` Expands all tabs into spaces.
`CharSequence` | `expandLine(int tabStop)` Expands all tabs into spaces.
`CharSequence` | `find(CharSequence regex)` Finds the first occurrence of a regular expression CharSequence within a CharSequence.
`CharSequence` | `find(CharSequence regex, Closure closure)` Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence.
`CharSequence` | `find(Pattern pattern)` Finds the first occurrence of a compiled regular expression Pattern within a CharSequence.
`CharSequence` | `find(Pattern pattern, Closure closure)` Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence.
`List` | `findAll(CharSequence regex)` Returns a (possibly empty) list of all occurrences of a regular expression (in CharSequence format) found within a CharSequence.
`List` | `findAll(CharSequence regex, Closure closure)` Finds all occurrences of a capturing regular expression CharSequence within a CharSequence.
`List` | `findAll(Pattern pattern)` Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.
`List` | `findAll(Pattern pattern, Closure closure)` Finds all occurrences of a compiled regular expression Pattern within a CharSequence.
`CharSequence` | `getAt(Collection indices)` Select a List of characters from a CharSequence using a Collection to identify the indices to be selected.
`CharSequence` | `getAt(EmptyRange range)` Support the range subscript operator for CharSequence or StringBuffer with EmptyRange
`CharSequence` | `getAt(int index)` Support the subscript operator for CharSequence.
`CharSequence` | `getAt(IntRange range)` Support the range subscript operator for CharSequence or StringBuffer with IntRange
`CharSequence` | `getAt(Range range)` Support the range subscript operator for CharSequence
`char[]` | `getChars()` Converts the given CharSequence into an array of characters.
`boolean` | `isAllWhitespace()` True if a CharSequence only contains whitespace characters.
`boolean` | `isBigDecimal()` Determine if a CharSequence can be parsed as a BigDecimal.
`boolean` | `isBigInteger()` Determine if a CharSequence can be parsed as a BigInteger.
`boolean` | `isCase(Object switchValue)` 'Case' implementation for a CharSequence, which simply calls the equivalent method for String.
`boolean` | `isDouble()` Determine if a CharSequence can be parsed as a Double.
`boolean` | `isFloat()` Determine if a CharSequence can be parsed as a Float.
`boolean` | `isInteger()` Determine if a CharSequence can be parsed as an Integer.
`boolean` | `isLong()` Determine if a CharSequence can be parsed as a Long.
`boolean` | `isNumber()` Determine if a CharSequence can be parsed as a Number.
`StringBuilder` | `leftShift(Object value)` Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence.
`boolean` | `matches(Pattern pattern)` Tells whether or not a CharSequence matches the given compiled regular expression Pattern.
`CharSequence` | `minus(Object target)` Remove a part of a CharSequence by replacing the first occurrence of target within self with '' and returns the result.
`CharSequence` | `multiply(Number factor)` Repeat a CharSequence a certain number of times.
`CharSequence` | `next()` This method is called by the ++ operator for the class CharSequence.
`CharSequence` | `normalize()` Return a CharSequence with linefeeds and carriage returns normalized to linefeeds.
`CharSequence` | `padLeft(Number numberOfChars)` Pad a CharSequence to a minimum length specified by `numberOfChars` by adding the space character to the left as many times as needed.
`CharSequence` | `padLeft(Number numberOfChars, CharSequence padding)` Pad a CharSequence to a minimum length specified by `numberOfChars`, adding the supplied padding CharSequence as many times as needed to the left.
`CharSequence` | `padRight(Number numberOfChars)` Pad a CharSequence to a minimum length specified by `numberOfChars` by adding the space character to the right as many times as needed.
`CharSequence` | `padRight(Number numberOfChars, CharSequence padding)` Pad a CharSequence to a minimum length specified by `numberOfChars`, adding the supplied padding CharSequence as many times as needed to the right.
`CharSequence` | `plus(Object value)` Appends the String representation of the given operand to this string.
`CharSequence` | `previous()` This method is called by the -- operator for the class CharSequence.
`List` | `readLines()` Return the lines of a CharSequence as a List of CharSequence.
`CharSequence` | `replaceAll(CharSequence regex, CharSequence replacement)` Replaces each substring of this CharSequence that matches the given regular expression with the given replacement.
`CharSequence` | `replaceAll(CharSequence regex, Closure closure)` Replaces all occurrences of a captured group by the result of a closure on that text.
`CharSequence` | `replaceAll(Pattern pattern, CharSequence replacement)` Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement.
`String` | `replaceAll(Pattern pattern, Closure closure)` Replaces all occurrences of a captured group by the result of a closure call on that text.
`String` | `replaceFirst(CharSequence regex, CharSequence replacement)` Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement.
`String` | `replaceFirst(CharSequence regex, Closure closure)` Replaces the first occurrence of a captured group by the result of a closure call on that text.
`CharSequence` | `replaceFirst(Pattern pattern, CharSequence replacement)` Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement.
`String` | `replaceFirst(Pattern pattern, Closure closure)` Replaces the first occurrence of a captured group by the result of a closure call on that text.
`CharSequence` | `reverse()` Creates a new CharSequence which is the reverse (backwards) of this string
`int` | `size()` Provide the standard Groovy `size()` method for `CharSequence`.
`CharSequence[]` | `split()` Convenience method to split a CharSequence (with whitespace as delimiter).
`Object` | `splitEachLine(CharSequence regex, Closure closure)` Iterates through the given CharSequence line by line, splitting each line using the given separator.
`Object` | `splitEachLine(Pattern pattern, Closure closure)` Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern.
`CharSequence` | `stripIndent()` Strip leading spaces from every line in a CharSequence.
`CharSequence` | `stripIndent(int numChars)` Strip `numChar` leading characters from every line in a CharSequence.
`CharSequence` | `stripMargin()` Strip leading whitespace/control characters followed by '|' from every line in a CharSequence.
`CharSequence` | `stripMargin(char marginChar)` Strip leading whitespace/control characters followed by `marginChar` from every line in a String.
`String` | `stripMargin(CharSequence marginChar)` Strip leading whitespace/control characters followed by `marginChar` from every line in a CharSequence.
`CharSequence` | `take(int num)` Returns the first `num` elements from this CharSequence.
`CharSequence` | `takeWhile(Closure condition)` Returns the longest prefix of this CharSequence where each element passed to the given closure evaluates to true.
`BigDecimal` | `toBigDecimal()` Parse a CharSequence into a BigDecimal
`BigInteger` | `toBigInteger()` Parse a CharSequence into a BigInteger
`Double` | `toDouble()` Parse a CharSequence into a Double
`Float` | `toFloat()` Parse a CharSequence into a Float
`Integer` | `toInteger()` Parse a CharSequence into an Integer
`List` | `toList()` Converts the given CharSequence into a List of CharSequence of one character.
`Long` | `toLong()` Parse a CharSequence into a Long
`Set` | `toSet()` Converts the given CharSequence into a Set of unique CharSequence of one character.
`Short` | `toShort()` Parse a CharSequence into a Short
`URI` | `toURI()` Transforms a CharSequence representing a URI into a URI object.
`URL` | `toURL()` Transforms a CharSequence representing a URL into a URL object.
`List` | `tokenize()` Tokenize a CharSequence (with a whitespace as the delimiter).
`List` | `tokenize(Character token)` Tokenize a CharSequence based on the given character delimiter.
`List` | `tokenize(CharSequence token)` Tokenize a CharSequence based on the given CharSequence delimiter.
`CharSequence` | `tr(CharSequence sourceSet, CharSequence replacementSet)` Translates a string by replacing characters from the sourceSet with characters from replacementSet.
`CharSequence` | `unexpand()` Replaces sequences of whitespaces with tabs using tabStops of size 8.
`CharSequence` | `unexpand(int tabStop)` Replaces sequences of whitespaces with tabs.
`CharSequence` | `unexpandLine(int tabStop)` Replaces sequences of whitespaces with tabs within a line.

Method Detail

### asBoolean

    public boolean asBoolean()

  Coerce a string (an instance of CharSequence) to a boolean value. A string is coerced to false if it is of length 0, and to true otherwise.

Returns:
  the boolean value

Since:
  1.7.0

### asType

    public Object asType(Class c)

  Provides a method to perform custom 'dynamic' type conversion to the given class using the `as` operator.

Parameters:
  `c` - the desired class.

Returns:
  the converted object

Since:
  1.8.2

See:
  String#asType(Class).

### bitwiseNegate

    public Pattern bitwiseNegate()

  Turns a CharSequence into a regular expression Pattern

Returns:
  the regular expression pattern

Since:
  1.8.2

### capitalize

    public CharSequence capitalize()

  Convenience method to capitalize the first letter of a CharSequence.

Returns:
  The capitalized CharSequence

Since:
  1.8.2

See:
  String#capitalize().

### center

    public CharSequence center(Number numberOfChars)

  Pad a CharSequence to a minimum length specified by `numberOfChars` by adding the space character around it as many times as needed so that it remains centered.

Parameters:
  `numberOfChars` - the total minimum number of characters of the resulting CharSequence.

Returns:
  the CharSequence centered with padded characters around it

Since:
  1.8.2

See:
  String#center(Number).

### center

    public CharSequence center(Number numberOfChars, CharSequence padding)

  Pad a CharSequence to a minimum length specified by `numberOfChars`, appending the supplied padding CharSequence around the original as many times as needed keeping it centered.

Parameters:
  `numberOfChars` - the total minimum number of characters of the resulting CharSequence.
  `padding` - the characters used for padding.

Returns:
  the CharSequence centered with padded characters around it

Since:
  1.8.2

See:
  String#center(Number, String).

### contains

    public boolean contains(CharSequence text)

  Provide an implementation of contains() like Collection#contains to make CharSequences more polymorphic.

Parameters:
  `text` - the CharSequence to look for.

Returns:
  true if this CharSequence contains the given text

Since:
  1.8.2

See:
  String#contains(String).

### count

    public int count(CharSequence text)

  Count the number of occurrences of a sub CharSequence.

Parameters:
  `text` - a sub CharSequence.

Returns:
  the number of occurrences of the given CharSequence inside this CharSequence

Since:
  1.8.2

See:
  String#count(String).

### denormalize

    public CharSequence denormalize()

  Return a CharSequence with lines (separated by LF, CR/LF, or CR) terminated by the platform specific line separator.

Returns:
  the denormalized CharSequence

Since:
  1.8.2

See:
  String#denormalize().

### drop

    public CharSequence drop(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:
  `num` - the number of characters to drop from this iterator.

Returns:
  a CharSequence consisting of all characters except the first `num` ones, or else an empty String, if this CharSequence has less than `num` characters.

Since:
  1.8.1

### dropWhile

    public CharSequence dropWhile(Closure condition)

  Create a suffix of the given CharSequence by dropping as many characters as possible from the front of the original CharSequence such that calling the given closure condition evaluates to true when passed each of the dropped characters.

      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:
  `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

### eachLine

    public Object eachLine(Closure closure)

  Iterates 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:
  `closure` - a closure.

Returns:
  the last value returned by the closure

Since:
  1.8.2

See:
  String#eachLine.

### eachLine

    public Object eachLine(int firstLine, Closure closure)

  Iterates 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:
  `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

Since:
  1.8.2

See:
  String#eachLine.

### eachMatch

    public String eachMatch(CharSequence regex, Closure closure)

  Process 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:
  `regex` - a Regex CharSequence.
  `closure` - a closure with one parameter or as much parameters as groups.

Returns:
  the source CharSequence

Since:
  1.8.2

See:
  String#eachMatch.

### eachMatch

    public String eachMatch(Pattern pattern, Closure closure)

  Process 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:
  `pattern` - a regex Pattern.
  `closure` - a closure with one parameter or as much parameters as groups.

Returns:
  the source CharSequence

Since:
  1.8.2

See:
  String#eachMatch.

### expand

    public CharSequence expand()

  Expands all tabs into spaces with tabStops of size 8.

Returns:
  The expanded CharSequence

Since:
  1.8.2

See:
  String#expand().

### expand

    public CharSequence expand(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:
  `tabStop` - The number of spaces a tab represents.

Returns:
  The expanded CharSequence

Since:
  1.8.2

See:
  String#expand(int).

### expandLine

    public CharSequence expandLine(int tabStop)

  Expands all tabs into spaces. Assumes the CharSequence represents a single line of text.

Parameters:
  `tabStop` - The number of spaces a tab represents.

Returns:
  The expanded CharSequence

Since:
  1.8.2

See:
  String#expandLine(int).

### find

    public CharSequence find(CharSequence regex)

  Finds the first occurrence of a regular expression CharSequence within a CharSequence.

Parameters:
  `regex` - the capturing regex.

Returns:
  a CharSequence containing the matched portion, or null if the regex doesn't match

Since:
  1.8.2

See:
  String#find.

### find

    public CharSequence find(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:
  `regex` - the capturing regex CharSequence.
  `closure` - the closure that will be passed the full match, plus each of the capturing groups.

Returns:
  a CharSequence containing the result of the closure, or null if the regex pattern doesn't match

Since:
  1.8.2

See:
  String#find.

### find

    public CharSequence find(Pattern pattern)

  Finds the first occurrence of a compiled regular expression Pattern within a CharSequence.

Parameters:
  `pattern` - the compiled regex Pattern.

Returns:
  a CharSequence containing the matched portion, or null if the regex pattern doesn't match

Since:
  1.8.2

See:
  String#find.

### find

    public CharSequence find(Pattern pattern, 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:
  `pattern` - the compiled regex Pattern.
  `closure` - the closure that will be passed the full match, plus each of the capturing groups.

Returns:
  a CharSequence containing the result of the closure, or null if the regex pattern doesn't match

Since:
  1.8.2

See:
  String#find.

### findAll

    public List findAll(CharSequence regex)

  Returns a (possibly empty) list of all occurrences of a regular expression (in CharSequence format) found within a CharSequence.

Parameters:
  `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:
  String#findAll(String).

### findAll

    public List findAll(CharSequence regex, Closure closure)

  Finds all occurrences of a capturing regular expression CharSequence within a CharSequence.

Parameters:
  `regex` - the capturing regex CharSequence.
  `closure` - will be passed the full match plus each of the capturing groups.

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:
  String#findAll.

### findAll

    public List findAll(Pattern pattern)

  Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.

Parameters:
  `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

See:
  String#findAll.

### findAll

    public List findAll(Pattern pattern, Closure closure)

  Finds all occurrences of a compiled regular expression Pattern within a CharSequence.

Parameters:
  `pattern` - the compiled regex Pattern.
  `closure` - will be passed the full match plus each of the capturing groups.

Returns:
  a List containing all full matches of the regex Pattern within the CharSequence, an empty list will be returned if there are no matches

Since:
  1.8.2

See:
  String#findAll.

### getAt

    public CharSequence getAt(Collection indices)

  Select a List of characters from a CharSequence using a Collection to identify the indices to be selected.

Parameters:
  `indices` - a Collection of indices.

Returns:
  a CharSequence consisting of the characters at the given indices

Since:
  1.0

### getAt

    public CharSequence getAt(EmptyRange range)

  Support the range subscript operator for CharSequence or StringBuffer with EmptyRange

Parameters:
  `range` - an EmptyRange.

Returns:
  the subsequence CharSequence

Since:
  1.5.0

### getAt

    public CharSequence getAt(int index)

  Support the subscript operator for CharSequence.

Parameters:
  `index` - the index of the Character to get.

Returns:
  the Character at the given index

Since:
  1.0

### getAt

    public CharSequence getAt(IntRange range)

  Support the range subscript operator for CharSequence or StringBuffer with IntRange

Parameters:
  `range` - an IntRange.

Returns:
  the subsequence CharSequence

Since:
  1.0

### getAt

    public CharSequence getAt(Range range)

  Support the range subscript operator for CharSequence

Parameters:
  `range` - a Range.

Returns:
  the subsequence CharSequence

Since:
  1.0

### getChars

    public char[] getChars()

  Converts the given CharSequence into an array of characters.

Returns:
  an array of characters

Since:
  1.8.2

See:
  String#getChars().

### isAllWhitespace

    public boolean isAllWhitespace()

  True if a CharSequence only contains whitespace characters.

Returns:
  true If all characters are whitespace characters

Since:
  1.8.2

See:
  String#isAllWhitespace().

### isBigDecimal

    public boolean isBigDecimal()

  Determine if a CharSequence can be parsed as a BigDecimal.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isBigDecimal().

### isBigInteger

    public boolean isBigInteger()

  Determine if a CharSequence can be parsed as a BigInteger.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isBigInteger().

### isCase

    public boolean isCase(Object switchValue)

  'Case' implementation for a CharSequence, which simply calls the equivalent method for String.

Parameters:
  `switchValue` - the switch value.

Returns:
  true if the switchValue's toString() equals the caseValue

Since:
  1.8.2

### isDouble

    public boolean isDouble()

  Determine if a CharSequence can be parsed as a Double.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isDouble().

### isFloat

    public boolean isFloat()

  Determine if a CharSequence can be parsed as a Float.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isFloat().

### isInteger

    public boolean isInteger()

  Determine if a CharSequence can be parsed as an Integer.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isInteger().

### isLong

    public boolean isLong()

  Determine if a CharSequence can be parsed as a Long.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isLong().

### isNumber

    public boolean isNumber()

  Determine if a CharSequence can be parsed as a Number. Synonym for 'isBigDecimal()'.

Returns:
  true if the CharSequence can be parsed

Since:
  1.8.2

See:
  String#isNumber().

### leftShift

    public StringBuilder leftShift(Object value)

  Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a CharSequence.

Parameters:
  `value` - an Object.

Returns:
  a StringBuilder built from this CharSequence

Since:
  1.8.2

### matches

    public boolean matches(Pattern pattern)

  Tells whether or not a CharSequence matches the given compiled regular expression Pattern.

Parameters:
  `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:
  String#matches(String).

### minus

    public CharSequence minus(Object target)

  Remove a part of a CharSequence by replacing the first occurrence of target within self with '' and returns the result.

Parameters:
  `target` - an object representing the part to remove.

Returns:
  a CharSequence minus the part to be removed

Since:
  1.8.2

See:
  String#minus(Object).

### multiply

    public CharSequence multiply(Number factor)

  Repeat a CharSequence a certain number of times.

Parameters:
  `factor` - the number of times the CharSequence should be repeated.

Returns:
  a CharSequence composed of a repetition

Since:
  1.8.2

### next

    public CharSequence next()

  This method is called by the ++ operator for the class CharSequence.

Returns:
  an incremented CharSequence

Since:
  1.8.2

See:
  String#next().

### normalize

    public CharSequence normalize()

  Return a CharSequence with linefeeds and carriage returns normalized to linefeeds.

Returns:
  the normalized CharSequence

Since:
  1.8.2

See:
  String#normalize().

### padLeft

    public CharSequence padLeft(Number numberOfChars)

  Pad a CharSequence to a minimum length specified by `numberOfChars` by adding the space character to the left as many times as needed.

Parameters:
  `numberOfChars` - the total minimum number of characters of the resulting CharSequence.

Returns:
  the CharSequence padded to the left

Since:
  1.8.2

See:
  CharSequence#padLeft(Number, CharSequence).

### padLeft

    public CharSequence padLeft(Number numberOfChars, CharSequence padding)

  Pad a CharSequence to a minimum length specified by `numberOfChars`, adding the supplied padding CharSequence as many times as needed to the left.

Parameters:
  `numberOfChars` - the total minimum number of characters of the resulting CharSequence.
  `padding` - the characters used for padding.

Returns:
  the CharSequence padded to the left

Since:
  1.8.2

See:
  String#padLeft(Number, String).

### padRight

    public CharSequence padRight(Number numberOfChars)

  Pad a CharSequence to a minimum length specified by `numberOfChars` by adding the space character to the right as many times as needed.

Parameters:
  `numberOfChars` - the total minimum number of characters of the resulting string.

Returns:
  the CharSequence padded to the right

Since:
  1.8.2

See:
  String#padRight(Number).

### padRight

    public CharSequence padRight(Number numberOfChars, CharSequence padding)

  Pad a CharSequence to a minimum length specified by `numberOfChars`, adding the supplied padding CharSequence as many times as needed to the right.

Parameters:
  `numberOfChars` - the total minimum number of characters of the resulting CharSequence.
  `padding` - the characters used for padding.

Returns:
  the CharSequence padded to the right

Since:
  1.8.2

See:
  String#padRight(Number, String).

### plus

    public CharSequence plus(Object value)

  Appends the String representation of the given operand to this string.

Parameters:
  `value` - any Object.

Returns:
  the new CharSequence with the object appended

Since:
  1.8.2

### previous

    public CharSequence previous()

  This method is called by the -- operator for the class CharSequence.

Returns:
  a CharSequence with a decremented digit at the end

Since:
  1.8.2

See:
  String#previous().

### readLines

    public List readLines()

  Return the lines of a CharSequence as a List of CharSequence.

Returns:
  a list of lines

Since:
  1.8.2

### replaceAll

    public CharSequence replaceAll(CharSequence regex, CharSequence replacement)

  Replaces each substring of this CharSequence that matches the given regular expression with the given replacement.

Parameters:
  `regex` - the capturing regex.
  `replacement` - the capturing regex.

Returns:
  a CharSequence with replaced content

Since:
  1.8.2

See:
  String#replaceAll(String, String).

### replaceAll

    public CharSequence replaceAll(CharSequence regex, Closure closure)

  Replaces all occurrences of a captured group by the result of a closure on that text.

Parameters:
  `regex` - the capturing regex.
  `closure` - the closure to apply on each captured group.

Returns:
  a CharSequence with replaced content

Since:
  1.8.2

See:
  String#replaceAll.

### replaceAll

    public CharSequence replaceAll(Pattern pattern, CharSequence replacement)

  Replaces all substrings of a CharSequence that match the given compiled regular expression with the given replacement.

Parameters:
  `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 resulting `CharSequence`

Since:
  1.8.2

See:
  String#replaceAll.

### replaceAll

    public String replaceAll(Pattern pattern, Closure closure)

  Replaces all occurrences of a captured group by the result of a closure call on that text.

Parameters:
  `pattern` - the capturing regex Pattern.
  `closure` - the closure to apply on each captured group.

Returns:
  a CharSequence with replaced content

Since:
  1.8.2

See:
  String#replaceAll.

### replaceFirst

    public String replaceFirst(CharSequence regex, CharSequence replacement)

  Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement.

Parameters:
  `regex` - the capturing regex.
  `replacement` - the capturing regex.

Returns:
  a CharSequence with replaced content

Since:
  1.8.2

See:
  String#replaceAll(String, String).

### replaceFirst

    public String replaceFirst(CharSequence regex, Closure closure)

  Replaces the first occurrence of a captured group by the result of a closure call on that text.

Parameters:
  `regex` - the capturing regex.
  `closure` - the closure to apply on the first captured group.

Returns:
  a CharSequence with replaced content

Since:
  1.8.2

See:
  String#replaceFirst.

### replaceFirst

    public CharSequence replaceFirst(Pattern pattern, CharSequence replacement)

  Replaces the first substring of a CharSequence that matches the given compiled regular expression with the given replacement.

Parameters:
  `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 resulting `CharSequence`

Since:
  1.8.2

See:
  String#replaceFirst.

### replaceFirst

    public String replaceFirst(Pattern pattern, Closure closure)

  Replaces the first occurrence of a captured group by the result of a closure call on that text.

Parameters:
  `pattern` - the capturing regex Pattern.
  `closure` - the closure to apply on the first captured group.

Returns:
  a CharSequence with replaced content

Since:
  1.8.2

See:
  String#replaceFirst.

### reverse

    public CharSequence reverse()

  Creates a new CharSequence which is the reverse (backwards) of this string

Returns:
  a new CharSequence with all the characters reversed.

Since:
  1.8.2

See:
  String#reverse().

### size

    public int size()

  Provide the standard Groovy `size()` method for `CharSequence`.

Returns:
  the length of the CharSequence

Since:
  1.8.2

### split

    public CharSequence[] split()

  Convenience method to split a CharSequence (with whitespace as delimiter). Similar to tokenize, but returns an Array of CharSequence instead of a List.

Returns:
  CharSequence[] result of split

Since:
  1.8.2

See:
  String#split().

### splitEachLine

    public Object splitEachLine(CharSequence regex, Closure closure)

  Iterates through the given CharSequence line by line, splitting each line using the given separator. The list of tokens for each line is then passed to the given closure.

Parameters:
  `regex` - the delimiting regular expression.
  `closure` - a closure.

Returns:
  the last value returned by the closure

Since:
  1.8.2

See:
  String#splitEachLine.

### splitEachLine

    public Object splitEachLine(Pattern pattern, Closure 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:
  `pattern` - the regular expression Pattern for the delimiter.
  `closure` - a closure.

Returns:
  the last value returned by the closure

Since:
  1.8.2

See:
  String#splitEachLine.

### stripIndent

    public CharSequence stripIndent()

  Strip 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.

Returns:
  the stripped CharSequence

Since:
  1.8.2

See:
  String#stripIndent().

### stripIndent

    public CharSequence stripIndent(int numChars)

  Strip `numChar` leading characters from every line in a CharSequence.

Parameters:
  `numChars` - The number of characters to strip.

Returns:
  the stripped CharSequence

Since:
  1.8.2

### stripMargin

    public CharSequence stripMargin()

  Strip leading whitespace/control characters followed by '|' from every line in a CharSequence.

Returns:
  the stripped CharSequence

Since:
  1.8.2

See:
  CharSequence#stripMargin(char).

### stripMargin

    public CharSequence stripMargin(char marginChar)

  Strip leading whitespace/control characters followed by `marginChar` from every line in a String.

Parameters:
  `marginChar` - Any character that serves as margin delimiter.

Returns:
  the stripped CharSequence

Since:
  1.8.2

See:
  String#stripMargin(char).

### stripMargin

    public String stripMargin(CharSequence marginChar)

  Strip leading whitespace/control characters followed by `marginChar` from every line in a CharSequence.

Parameters:
  `marginChar` - Any character that serves as margin delimiter.

Returns:
  the stripped CharSequence

Since:
  1.8.2

See:
  String#stripMargin(String).

### take

    public CharSequence take(int num)

  Returns the first `num` elements from this CharSequence.

      def text = "Groovy"
      assert text.take( 0 ) == ''
      assert text.take( 2 ) == 'Gr'
      assert text.take( 7 ) == 'Groovy'

Parameters:
  `num` - the number of chars to take from this CharSequence.

Returns:
  a CharSequence consisting of the first `num` chars, or else the whole CharSequence if it has less then `num` elements.

Since:
  1.8.1

### takeWhile

    public CharSequence takeWhile(Closure condition)

  Returns 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:
  `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

### toBigDecimal

    public BigDecimal toBigDecimal()

  Parse a CharSequence into a BigDecimal

Returns:
  a BigDecimal

Since:
  1.8.2

See:
  String#toBigDecimal().

### toBigInteger

    public BigInteger toBigInteger()

  Parse a CharSequence into a BigInteger

Returns:
  a BigInteger

Since:
  1.8.2

See:
  String#toBigInteger().

### toDouble

    public Double toDouble()

  Parse a CharSequence into a Double

Returns:
  a Double

Since:
  1.8.2

See:
  String#toDouble().

### toFloat

    public Float toFloat()

  Parse a CharSequence into a Float

Returns:
  a Float

Since:
  1.8.2

See:
  String#toFloat().

### toInteger

    public Integer toInteger()

  Parse a CharSequence into an Integer

Returns:
  an Integer

Since:
  1.8.2

See:
  String#toInteger().

### toList

    public List toList()

  Converts the given CharSequence into a List of CharSequence of one character.

Returns:
  a List of characters (a 1-character CharSequence)

Since:
  1.8.2

See:
  String#toSet().

### toLong

    public Long toLong()

  Parse a CharSequence into a Long

Returns:
  a Long

Since:
  1.8.2

See:
  String#toLong().

### toSet

    public Set toSet()

  Converts the given CharSequence into a Set of unique CharSequence of one character.

Returns:
  a Set of unique character CharSequence (each a 1-character CharSequence)

Since:
  1.8.2

See:
  String#toSet().

### toShort

    public Short toShort()

  Parse a CharSequence into a Short

Returns:
  a Short

Since:
  1.8.2

See:
  String#toShort().

### toURI

    public URI toURI()

  Transforms a CharSequence representing a URI into a URI object.

Returns:
  a URI

Since:
  1.8.2

### toURL

    public URL toURL()

  Transforms a CharSequence representing a URL into a URL object.

Returns:
  a URL

Since:
  1.8.2

### tokenize

    public List tokenize()

  Tokenize a CharSequence (with a whitespace as the delimiter).

Returns:
  a List of tokens

Since:
  1.8.2

See:
  String#tokenize().

### tokenize

    public List tokenize(Character token)

  Tokenize a CharSequence based on the given character delimiter.

Parameters:
  `token` - the delimiter.

Returns:
  a List of tokens

Since:
  1.8.2

See:
  String#tokenize(Character).

### tokenize

    public List tokenize(CharSequence token)

  Tokenize a CharSequence based on the given CharSequence delimiter.

Parameters:
  `token` - the delimiter.

Returns:
  a List of tokens

Since:
  1.8.2

See:
  String#tokenize(String).

### tr

    public CharSequence tr(CharSequence sourceSet, CharSequence replacementSet)

  Translates a string by replacing characters from the sourceSet with characters from replacementSet.

Parameters:
  `sourceSet` - the set of characters to translate from.
  `replacementSet` - the set of replacement characters.

Returns:
  The resulting translated `CharSequence`

Since:
  1.8.2

See:
  String#tr(String, String).

### unexpand

    public CharSequence unexpand()

  Replaces sequences of whitespaces with tabs using tabStops of size 8.

Returns:
  The unexpanded CharSequence

Since:
  1.8.2

See:
  String#unexpand().

### unexpand

    public CharSequence unexpand(int tabStop)

  Replaces sequences of whitespaces with tabs.

Parameters:
  `tabStop` - The number of spaces a tab represents.

Returns:
  The unexpanded CharSequence

Since:
  1.8.2

See:
  String#unexpand(int).

### unexpandLine

    public CharSequence unexpandLine(int tabStop)

  Replaces sequences of whitespaces with tabs within a line.

Parameters:
  `tabStop` - The number of spaces a tab represents.

Returns:
  The unexpanded CharSequence

Since:
  1.8.2

See:
  String#unexpandLine(int).

Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK