Packages

final class StringOps extends AnyVal

Provides extension methods for strings.

Some of these methods treat strings as a plain collection of Chars without any regard for Unicode handling. Unless the user takes Unicode handling in to account or makes sure the strings don't require such handling, these methods may result in unpaired or invalidly paired surrogate code units.

Source
StringOps.scala
Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. StringOps
  2. AnyVal
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new StringOps(s: String)

Value Members

  1. final def !=(arg0: Any): Boolean

    Test two objects for inequality.

    Test two objects for inequality.

    returns

    true if !(this == that), false otherwise.

    Definition Classes
    Any
  2. final def ##: Int

    Equivalent to x.hashCode except for boxed numeric types and null.

    Equivalent to x.hashCode except for boxed numeric types and null. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For null returns a hashcode where null.hashCode throws a NullPointerException.

    returns

    a hash value consistent with ==

    Definition Classes
    Any
  3. def *(n: Int): String

    Return the current string concatenated n times.

  4. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from StringOps toany2stringadd[StringOps] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  5. def ++(xs: String): String

    Alias for concat

  6. def ++(suffix: IterableOnce[Char]): String

    Alias for concat

    Alias for concat

    Annotations
    @inline()
  7. def ++[B >: Char](suffix: Iterable[B]): immutable.IndexedSeq[B]

    Alias for concat

    Alias for concat

    Annotations
    @inline()
  8. def ++:(prefix: String): String

    Alias for prependedAll

    Alias for prependedAll

    Annotations
    @inline()
  9. def ++:[B >: Char](prefix: IterableOnce[B]): immutable.IndexedSeq[B]

    Alias for prependedAll

    Alias for prependedAll

    Annotations
    @inline()
  10. def +:(c: Char): String

    Alias for prepended

    Alias for prepended

    Annotations
    @inline()
  11. def +:[B >: Char](elem: B): immutable.IndexedSeq[B]

    Alias for prepended

    Alias for prepended

    Annotations
    @inline()
  12. def ->[B](y: B): (StringOps, B)
    Implicit
    This member is added by an implicit conversion from StringOps toArrowAssoc[StringOps] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  13. def :+(c: Char): String

    Alias for appended

    Alias for appended

    Annotations
    @inline()
  14. def :+[B >: Char](elem: B): immutable.IndexedSeq[B]

    Alias for appended

    Alias for appended

    Annotations
    @inline()
  15. def :++(suffix: String): String

    Alias for appendedAll

    Alias for appendedAll

    Annotations
    @inline()
  16. def :++[B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B]

    Alias for appendedAll

    Alias for appendedAll

    Annotations
    @inline()
  17. def <(that: String): Boolean

    Returns true if this is less than that

  18. def <=(that: String): Boolean

    Returns true if this is less than or equal to that.

  19. final def ==(arg0: Any): Boolean

    Test two objects for equality.

    Test two objects for equality. The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    Definition Classes
    Any
  20. def >(that: String): Boolean

    Returns true if this is greater than that.

  21. def >=(that: String): Boolean

    Returns true if this is greater than or equal to that.

  22. final def addString(b: mutable.StringBuilder, start: String, sep: String, end: String): b.type

    Appends this string to a string builder using start, end and separator strings.

  23. final def addString(b: mutable.StringBuilder, sep: String): b.type

    Appends this string to a string builder using a separator string.

    Appends this string to a string builder using a separator string.

    Annotations
    @inline()
  24. final def addString(b: mutable.StringBuilder): b.type

    Appends this string to a string builder.

    Appends this string to a string builder.

    Annotations
    @inline()
  25. def appended(c: Char): String

    A copy of the string with an element appended

  26. def appended[B >: Char](elem: B): immutable.IndexedSeq[B]

    A copy of the string with an element appended

  27. def appendedAll(suffix: String): String

    A copy of the string with another string appended

    A copy of the string with another string appended

    Annotations
    @inline()
  28. def appendedAll[B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B]

    A copy of the string with all elements from a collection appended

    A copy of the string with all elements from a collection appended

    Annotations
    @inline()
  29. def apply(i: Int): Char

    Get the char at the specified index.

    Get the char at the specified index.

    Annotations
    @inline()
  30. final def asInstanceOf[T0]: T0

    Forces the compiler to treat the receiver object as having type T0, even though doing so may violate type safety.

    Forces the compiler to treat the receiver object as having type T0, even though doing so may violate type safety.

    This method is useful when you believe you have type information the compiler doesn't, and it also isn't possible to check the type at runtime. In such situations, skipping type safety is the only option.

    It is platform dependent whether asInstanceOf has any effect at runtime. It might do a runtime type test on the erasure of T0, insert a conversion (such as boxing/unboxing), fill in a default value, or do nothing at all.

    In particular, asInstanceOf is not a type test. It does **not** mean:

    this match {
     case x: T0 => x
     case _     => throw ClassCastException("...")

    Use pattern matching or isInstanceOf for type testing instead.

    Situations where asInstanceOf is useful:

    • when flow analysis fails to deduce T0 automatically
    • when down-casting a type parameter or an abstract type member (which cannot be checked at runtime due to type erasure) If there is any doubt and you are able to type test instead, you should do so.

    Be careful of using asInstanceOf when T0 is a primitive type. When T0 is primitive, asInstanceOf may insert a conversion instead of a type test. If your intent is to convert, use a toT method (x.toChar, x.toByte, etc.).

    returns

    the receiver object.

    Definition Classes
    Any
    Exceptions thrown

    ClassCastException if the receiver is not an instance of the erasure of T0, if that can be checked on this platform

  31. def capitalize: String

    Returns this string with first character converted to upper case.

    Returns this string with first character converted to upper case. If the first character of the string is capitalized, it is returned unchanged. This method does not convert characters outside the Basic Multilingual Plane (BMP).

  32. def charStepper: IntStepper with EfficientSplit

    Steps over characters in this string.

    Steps over characters in this string. Values are packed in Int for efficiency and compatibility with Java 8 Streams which have an efficient specialization for Int.

    Annotations
    @inline()
  33. def codePointStepper: IntStepper with EfficientSplit

    Steps over code points in this string.

    Steps over code points in this string.

    Annotations
    @inline()
  34. def collect[B](pf: PartialFunction[Char, B]): immutable.IndexedSeq[B]

    Builds a new collection by applying a partial function to all chars of this String on which the function is defined.

    Builds a new collection by applying a partial function to all chars of this String on which the function is defined.

    B

    the element type of the returned collection.

    pf

    the partial function which filters and maps the String.

    returns

    a new collection resulting from applying the given partial function pf to each char on which it is defined and collecting the results.

  35. def collect(pf: PartialFunction[Char, Char]): String

    Builds a new String by applying a partial function to all chars of this String on which the function is defined.

    Builds a new String by applying a partial function to all chars of this String on which the function is defined.

    pf

    the partial function which filters and maps the String.

    returns

    a new String resulting from applying the given partial function pf to each char on which it is defined and collecting the results.

  36. def combinations(n: Int): Iterator[String]

    Iterates over combinations of elements.

    Iterates over combinations of elements.

    A combination of length n is a sequence of n elements selected in order of their first index in this sequence.

    For example, "xyx" has two combinations of length 2. The x is selected first: "xx", "xy". The sequence "yx" is not returned as a combination because it is subsumed by "xy".

    If there is more than one way to generate the same combination, only one will be returned.

    For example, the result "xy" arbitrarily selected one of the x elements.

    As a further illustration, "xyxx" has three different ways to generate "xy" because there are three elements x to choose from. Moreover, there are three unordered pairs "xx" but only one is returned.

    It is not specified which of these equal combinations is returned. It is an implementation detail that should not be relied on. For example, the combination "xx" does not necessarily contain the first x in this sequence. This behavior is observable if the elements compare equal but are not identical.

    As a consequence, "xyx".combinations(3).next() is "xxy": the combination does not reflect the order of the original sequence, but the order in which elements were selected, by "first index"; the order of each x element is also arbitrary.

    returns

    An Iterator which traverses the n-element combinations of this string.

    Example:
    1. "abbbc".combinations(2).foreach(println)
      // ab
      // ac
      // bb
      // bc
      "bab".combinations(2).foreach(println)
      // bb
      // ba
    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  37. def compare(that: String): Int
  38. def concat(suffix: String): String

    Returns a new string containing the chars from this string followed by the chars from the right hand operand.

    Returns a new string containing the chars from this string followed by the chars from the right hand operand.

    suffix

    the string to append.

    returns

    a new string which contains all chars of this string followed by all chars of suffix.

    Annotations
    @inline()
  39. def concat(suffix: IterableOnce[Char]): String

    Returns a new string containing the chars from this string followed by the chars from the right hand operand.

    Returns a new string containing the chars from this string followed by the chars from the right hand operand.

    suffix

    the collection to append.

    returns

    a new string which contains all chars of this string followed by all chars of suffix.

  40. def concat[B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B]

    Returns a new collection containing the chars from this string followed by the elements from the right hand operand.

    Returns a new collection containing the chars from this string followed by the elements from the right hand operand.

    suffix

    the collection to append.

    returns

    a new collection which contains all chars of this string followed by all elements of suffix.

  41. def contains(elem: Char): Boolean

    Tests whether this string contains the given character.

    Tests whether this string contains the given character.

    elem

    the character to test.

    returns

    true if this string has an element that is equal (as determined by ==) to elem, false otherwise.

  42. def copyToArray(xs: Array[Char], start: Int, len: Int): Int

    Copy chars of this string to an array.

    Copy chars of this string to an array. Fills the given array xs starting at index start with at most len chars. Copying will stop once either the entire string has been copied, or the end of the array is reached or len chars have been copied.

    xs

    the array to fill.

    start

    the starting index.

    len

    the maximal number of elements to copy.

  43. def copyToArray(xs: Array[Char], start: Int): Int

    Copy chars of this string to an array.

    Copy chars of this string to an array. Fills the given array xs starting at index start. Copying will stop once either the entire string has been copied or the end of the array is reached

    xs

    the array to fill.

    start

    the starting index.

    Annotations
    @inline()
  44. def copyToArray(xs: Array[Char]): Int

    Copy chars of this string to an array.

    Copy chars of this string to an array. Fills the given array xs starting at index 0. Copying will stop once either the entire string has been copied or the end of the array is reached

    xs

    the array to fill.

    Annotations
    @inline()
  45. def count(p: (Char) => Boolean): Int

    Counts the number of chars in this string which satisfy a predicate

  46. def diff[B >: Char](that: Seq[B]): String

    Computes the multiset difference between this string and another sequence.

    Computes the multiset difference between this string and another sequence.

    that

    the sequence of chars to remove

    returns

    a new string which contains all chars of this string except some of occurrences of elements that also appear in that. If an element value x appears n times in that, then the first n occurrences of x will not form part of the result, but any following occurrences will.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  47. def distinct: String

    Selects all distinct chars of this string ignoring the duplicates.

    Selects all distinct chars of this string ignoring the duplicates.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  48. def distinctBy[B](f: (Char) => B): String

    Selects all distinct chars of this string ignoring the duplicates as determined by == after applying the transforming function f.

    Selects all distinct chars of this string ignoring the duplicates as determined by == after applying the transforming function f.

    B

    the type of the elements after being transformed by f

    f

    The transforming function whose result is used to determine the uniqueness of each element

    returns

    a new string consisting of all the chars of this string without duplicates.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  49. def drop(n: Int): String

    The rest of the string without its n first chars.

    The rest of the string without its n first chars.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  50. def dropRight(n: Int): String

    The rest of the string without its n last chars.

    The rest of the string without its n last chars.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  51. def dropWhile(p: (Char) => Boolean): String

    Drops longest prefix of chars that satisfy a predicate.

    Drops longest prefix of chars that satisfy a predicate.

    p

    The predicate used to test elements.

    returns

    the longest suffix of this string whose first element does not satisfy the predicate p.

  52. def ensuring(cond: (StringOps) => Boolean, msg: => Any): StringOps
    Implicit
    This member is added by an implicit conversion from StringOps toEnsuring[StringOps] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  53. def ensuring(cond: (StringOps) => Boolean): StringOps
    Implicit
    This member is added by an implicit conversion from StringOps toEnsuring[StringOps] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  54. def ensuring(cond: Boolean, msg: => Any): StringOps
    Implicit
    This member is added by an implicit conversion from StringOps toEnsuring[StringOps] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  55. def ensuring(cond: Boolean): StringOps
    Implicit
    This member is added by an implicit conversion from StringOps toEnsuring[StringOps] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  56. def exists(p: (Char) => Boolean): Boolean

    Tests whether a predicate holds for at least one char of this string.

  57. def filter(pred: (Char) => Boolean): String

    Selects all chars of this string which satisfy a predicate.

  58. def filterNot(pred: (Char) => Boolean): String

    Selects all chars of this string which do not satisfy a predicate.

    Selects all chars of this string which do not satisfy a predicate.

    Annotations
    @inline()
  59. def find(p: (Char) => Boolean): Option[Char]

    Finds the first char of the string satisfying a predicate, if any.

    Finds the first char of the string satisfying a predicate, if any.

    p

    the predicate used to test elements.

    returns

    an option value containing the first element in the string that satisfies p, or None if none exists.

  60. def flatMap(f: (Char) => String): String

    Builds a new string by applying a function to all chars of this string and using the elements of the resulting strings.

    Builds a new string by applying a function to all chars of this string and using the elements of the resulting strings.

    f

    the function to apply to each char.

    returns

    a new string resulting from applying the given string-valued function f to each char of this string and concatenating the results.

  61. def flatMap[B](f: (Char) => IterableOnce[B]): immutable.IndexedSeq[B]

    Builds a new collection by applying a function to all chars of this string and using the elements of the resulting collections.

    Builds a new collection by applying a function to all chars of this string and using the elements of the resulting collections.

    f

    the function to apply to each char.

    returns

    a new collection resulting from applying the given collection-valued function f to each char of this string and concatenating the results.

  62. def fold[A1 >: Char](z: A1)(op: (A1, A1) => A1): A1

    Alias for foldLeft.

    Alias for foldLeft.

    The type parameter is more restrictive than for foldLeft to be consistent with IterableOnceOps.fold.

    A1

    The type parameter for the binary operator, a supertype of Char.

    z

    An initial value.

    op

    A binary operator.

    returns

    The result of applying op to z and all chars in this string, going left to right. Returns z if this string is empty.

    Annotations
    @inline()
  63. def foldLeft[B](z: B)(op: (B, Char) => B): B

    Applies the given binary operator op to the given initial value z and all chars in this string, going left to right.

    Applies the given binary operator op to the given initial value z and all chars in this string, going left to right. Returns the initial value if this string is empty.

    If x1, x2, ..., xn are the chars in this string, the result is op( op( ... op( op(z, x1), x2) ... ), xn).

    B

    The result type of the binary operator.

    z

    An initial value.

    op

    A binary operator.

    returns

    The result of applying op to z and all chars in this string, going left to right. Returns z if this string is empty.

  64. def foldRight[B](z: B)(op: (Char, B) => B): B

    Applies the given binary operator op to all chars in this string and the given initial value z, going right to left.

    Applies the given binary operator op to all chars in this string and the given initial value z, going right to left. Returns the initial value if this string is empty.

    If x1, x2, ..., xn are the chars in this string, the result is op(x1, op(x2, op( ... op(xn, z) ... ))).

    B

    The result type of the binary operator.

    z

    An initial value.

    op

    A binary operator.

    returns

    The result of applying op to all chars in this string and z, going right to left. Returns z if this string is empty.

  65. def forall(p: (Char) => Boolean): Boolean

    Tests whether a predicate holds for all chars of this string.

    Tests whether a predicate holds for all chars of this string.

    p

    the predicate used to test elements.

    returns

    true if this string is empty or the given predicate p holds for all chars of this string, otherwise false.

  66. def foreach[U](f: (Char) => U): Unit

    Apply f to each element for its side effects.

    Apply f to each element for its side effects. Note: [U] parameter needed to help scalac's type inference.

  67. def format(args: Any*): String

    Uses the underlying string as a pattern (in a fashion similar to printf in C), and uses the supplied arguments to fill in the holes.

    Uses the underlying string as a pattern (in a fashion similar to printf in C), and uses the supplied arguments to fill in the holes.

    The interpretation of the formatting patterns is described in java.util.Formatter, with the addition that classes deriving from ScalaNumber (such as scala.BigInt and scala.BigDecimal) are unwrapped to pass a type which Formatter understands.

    See scala.StringContext#f for a formatting interpolator that checks the format string at compilation.

    args

    the arguments used to instantiating the pattern.

    Exceptions thrown

    java.util.IllegalFormatException if the format contains syntax or conversion errors

  68. def formatLocal(l: Locale, args: Any*): String

    Like format(args*) but takes an initial Locale parameter which influences formatting as in java.lang.String's format.

    Like format(args*) but takes an initial Locale parameter which influences formatting as in java.lang.String's format.

    The interpretation of the formatting patterns is described in java.util.Formatter, with the addition that classes deriving from ScalaNumber (such as scala.BigInt and scala.BigDecimal) are unwrapped to pass a type which Formatter understands.

    l

    an instance of java.util.Locale

    args

    the arguments used to instantiating the pattern.

    Exceptions thrown

    java.util.IllegalFormatException if the format contains syntax or conversion errors

  69. def getClass(): Class[_ <: AnyVal]

    Returns the runtime class representation of the object.

    Returns the runtime class representation of the object.

    returns

    a class object corresponding to the runtime type of the receiver.

    Definition Classes
    AnyValAny
  70. def groupBy[K](f: (Char) => K): immutable.Map[K, String]

    Partitions this string into a map of strings according to some discriminator function.

    Partitions this string into a map of strings according to some discriminator function.

    K

    the type of keys returned by the discriminator function.

    f

    the discriminator function.

    returns

    A map from keys to strings such that the following invariant holds:

    (xs groupBy f)(k) = xs filter (x => f(x) == k)

    That is, every key k is bound to a string of those elements x for which f(x) equals k.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  71. def grouped(size: Int): Iterator[String]

    Partitions elements in fixed size strings.

    Partitions elements in fixed size strings.

    size

    the number of elements per group

    returns

    An iterator producing strings of size size, except the last will be less than size size if the elements don't divide evenly.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

    See also

    scala.collection.Iterator, method grouped

  72. def head: Char

    Selects the first char of this string.

    Selects the first char of this string.

    returns

    the first char of this string.

    Exceptions thrown

    NoSuchElementException if the string is empty.

  73. def headOption: Option[Char]

    Optionally selects the first char.

    Optionally selects the first char.

    returns

    the first char of this string if it is nonempty, None if it is empty.

  74. def indexWhere(p: (Char) => Boolean, from: Int = 0): Int

    Finds index of the first char satisfying some predicate after or at some start index.

    Finds index of the first char satisfying some predicate after or at some start index.

    p

    the predicate used to test elements.

    from

    the start index

    returns

    the index >= from of the first element of this string that satisfies the predicate p, or -1, if none exists.

  75. def indices: Range

    Produces the range of all indices of this string.

    Produces the range of all indices of this string.

    returns

    a Range value from 0 to one less than the length of this string.

  76. def init: String

    The initial part of the string without its last char.

    The initial part of the string without its last char.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  77. def inits: Iterator[String]

    Iterates over the inits of this string.

    Iterates over the inits of this string. The first value will be this string and the final one will be an empty string, with the intervening values the results of successive applications of init.

    returns

    an iterator over all the inits of this string

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  78. def intersect[B >: Char](that: Seq[B]): String

    Computes the multiset intersection between this string and another sequence.

    Computes the multiset intersection between this string and another sequence.

    that

    the sequence of chars to intersect with.

    returns

    a new string which contains all chars of this string which also appear in that. If an element value x appears n times in that, then the first n occurrences of x will be retained in the result, but any following occurrences will be omitted.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  79. final def isInstanceOf[T0]: Boolean

    Test whether the dynamic type of the receiver object has the same erasure as T0.

    Test whether the dynamic type of the receiver object has the same erasure as T0.

    Depending on what T0 is, the test is done in one of the below ways:

    • T0 is a non-parameterized class type, e.g. BigDecimal: this method returns true if the value of the receiver object is a BigDecimal or a subtype of BigDecimal.
    • T0 is a parameterized class type, e.g. List[Int]: this method returns true if the value of the receiver object is some List[X] for any X. For example, List(1, 2, 3).isInstanceOf[List[String]] will return true.
    • T0 is some singleton type x.type or literal x: this method returns this.eq(x). For example, x.isInstanceOf[1] is equivalent to x.eq(1)
    • T0 is an intersection X with Y or X & Y: this method is equivalent to x.isInstanceOf[X] && x.isInstanceOf[Y]
    • T0 is a union X | Y: this method is equivalent to x.isInstanceOf[X] || x.isInstanceOf[Y]
    • T0 is a type parameter or an abstract type member: this method is equivalent to isInstanceOf[U] where U is T0's upper bound, Any if T0 is unbounded. For example, x.isInstanceOf[A] where A is an unbounded type parameter will return true for any value of x.

    This is exactly equivalent to the type pattern _: T0

    returns

    true if the receiver object is an instance of erasure of type T0; false otherwise.

    Definition Classes
    Any
    Note

    due to the unexpectedness of List(1, 2, 3).isInstanceOf[List[String]] returning true and x.isInstanceOf[A] where A is a type parameter or abstract member returning true, these forms issue a warning.

  80. def iterator: Iterator[Char]

    Iterator can be used only once

  81. def knownSize: Int
    Annotations
    @inline()
  82. def last: Char

    Selects the last char of this string.

    Selects the last char of this string.

    returns

    the last char of this string.

    Exceptions thrown

    NoSuchElementException if the string is empty.

  83. def lastIndexWhere(p: (Char) => Boolean, end: Int = Int.MaxValue): Int

    Finds index of the last char satisfying some predicate before or at some end index.

    Finds index of the last char satisfying some predicate before or at some end index.

    p

    the predicate used to test elements.

    end

    the end index

    returns

    the index <= end of the last element of this string that satisfies the predicate p, or -1, if none exists.

  84. def lastOption: Option[Char]

    Optionally selects the last char.

    Optionally selects the last char.

    returns

    the last char of this string if it is nonempty, None if it is empty.

  85. def lazyZip[B](that: Iterable[B]): LazyZip2[Char, B, String]

    Analogous to zip except that the elements in each collection are not consumed until a strict operation is invoked on the returned LazyZip2 decorator.

    Analogous to zip except that the elements in each collection are not consumed until a strict operation is invoked on the returned LazyZip2 decorator.

    Calls to lazyZip can be chained to support higher arities (up to 4) without incurring the expense of constructing and deconstructing intermediary tuples.

    val xs = List(1, 2, 3)
    val res = (xs lazyZip xs lazyZip xs lazyZip xs).map((a, b, c, d) => a + b + c + d)
    // res == List(4, 8, 12)
    B

    the type of the second element in each eventual pair

    that

    the iterable providing the second element of each eventual pair

    returns

    a decorator LazyZip2 that allows strict operations to be performed on the lazily evaluated pairs or chained calls to lazyZip. Implicit conversion to Iterable[(A, B)] is also supported.

  86. def lengthCompare(len: Int): Int
  87. def lengthIs: Int
  88. def linesIterator: Iterator[String]

    Lines in this string, where a line is terminated by "\n", "\r", "\r\n", or the end of the string.

    Lines in this string, where a line is terminated by "\n", "\r", "\r\n", or the end of the string. A line may be empty. Line terminators are removed.

  89. def linesWithSeparators: Iterator[String]

    Return an iterator of all lines embedded in this string, including trailing line separator characters.

    Return an iterator of all lines embedded in this string, including trailing line separator characters.

    The empty string yields an empty iterator.

  90. def map(f: (Char) => Char): String

    Builds a new string by applying a function to all chars of this string.

    Builds a new string by applying a function to all chars of this string.

    f

    the function to apply to each char.

    returns

    a new string resulting from applying the given function f to each char of this string and collecting the results.

  91. def map[B](f: (Char) => B): immutable.IndexedSeq[B]

    Builds a new collection by applying a function to all chars of this string.

    Builds a new collection by applying a function to all chars of this string.

    f

    the function to apply to each char.

    returns

    a new collection resulting from applying the given function f to each char of this string and collecting the results.

  92. final def mkString: String

    Returns this string

    Returns this string

    Annotations
    @inline()
  93. final def mkString(sep: String): String

    Displays all elements of this string in a string using a separator string.

    Displays all elements of this string in a string using a separator string.

    sep

    the separator string.

    returns

    In the resulting string the chars of this string are separated by the string sep.

    Annotations
    @inline()
    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  94. final def mkString(start: String, sep: String, end: String): String

    Displays all elements of this string in a string using start, end, and separator strings.

    Displays all elements of this string in a string using start, end, and separator strings.

    start

    the starting string.

    sep

    the separator string.

    end

    the ending string.

    returns

    The resulting string begins with the string start and ends with the string end. Inside, the string chars of this string are separated by the string sep.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  95. def nonEmpty: Boolean

    Tests whether the string is not empty.

    Tests whether the string is not empty.

    Annotations
    @inline()
  96. def padTo(len: Int, elem: Char): String

    Returns a string with a char appended until a given target length is reached.

    Returns a string with a char appended until a given target length is reached.

    len

    the target length

    elem

    the padding value

    returns

    a string consisting of this string followed by the minimal number of occurrences of elem so that the resulting string has a length of at least len.

  97. def padTo[B >: Char](len: Int, elem: B): immutable.IndexedSeq[B]

    Returns a collection with an element appended until a given target length is reached.

    Returns a collection with an element appended until a given target length is reached.

    len

    the target length

    elem

    the padding value

    returns

    a collection consisting of this string followed by the minimal number of occurrences of elem so that the resulting collection has a length of at least len.

  98. def partition(p: (Char) => Boolean): (String, String)

    A pair of, first, all chars that satisfy predicate p and, second, all chars that do not.

  99. def partitionMap(f: (Char) => Either[Char, Char]): (String, String)

    Applies a function f to each character of the string and returns a pair of strings: the first one made of those characters returned by f that were wrapped in scala.util.Left, and the second one made of those wrapped in scala.util.Right.

    Applies a function f to each character of the string and returns a pair of strings: the first one made of those characters returned by f that were wrapped in scala.util.Left, and the second one made of those wrapped in scala.util.Right.

    Example:

    val xs = "1one2two3three" partitionMap { c =>
      if (c > 'a') Left(c) else Right(c)
    }
    // xs == ("onetwothree", "123")
    f

    the 'split function' mapping the elements of this string to an scala.util.Either

    returns

    a pair of strings: the first one made of those characters returned by f that were wrapped in scala.util.Left, and the second one made of those wrapped in scala.util.Right.

  100. def patch(from: Int, other: String, replaced: Int): String

    Produces a new string where a slice of characters in this string is replaced by another string.

    Produces a new string where a slice of characters in this string is replaced by another string.

    Patching at negative indices is the same as patching starting at 0. Patching at indices at or larger than the length of the original string appends the patch to the end. If more values are replaced than actually exist, the excess is ignored.

    from

    the index of the first replaced char

    other

    the replacement string

    replaced

    the number of chars to drop in the original string

    returns

    a new string consisting of all chars of this string except that replaced chars starting from from are replaced by other.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  101. def patch(from: Int, other: IterableOnce[Char], replaced: Int): String

    Produces a new collection where a slice of characters in this string is replaced by another collection.

    Produces a new collection where a slice of characters in this string is replaced by another collection.

    Patching at negative indices is the same as patching starting at 0. Patching at indices at or larger than the length of the original string appends the patch to the end. If more values are replaced than actually exist, the excess is ignored.

    from

    the index of the first replaced char

    other

    the replacement string

    replaced

    the number of chars to drop in the original string

    returns

    a new string consisting of all chars of this string except that replaced chars starting from from are replaced by other.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  102. def patch[B >: Char](from: Int, other: IterableOnce[B], replaced: Int): immutable.IndexedSeq[B]

    Produces a new collection where a slice of characters in this string is replaced by another collection.

    Produces a new collection where a slice of characters in this string is replaced by another collection.

    Patching at negative indices is the same as patching starting at 0. Patching at indices at or larger than the length of the original string appends the patch to the end. If more values are replaced than actually exist, the excess is ignored.

    from

    the index of the first replaced char

    other

    the replacement collection

    replaced

    the number of chars to drop in the original string

    returns

    a new collection consisting of all chars of this string except that replaced chars starting from from are replaced by other.

  103. def permutations: Iterator[String]

    Iterates over distinct permutations of elements.

    Iterates over distinct permutations of elements.

    returns

    An Iterator which traverses the distinct permutations of this string.

    Example:
    1. "abb".permutations.foreach(println)
      // abb
      // bab
      // bba
    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  104. def prepended(c: Char): String

    A copy of the string with an char prepended

  105. def prepended[B >: Char](elem: B): immutable.IndexedSeq[B]

    A copy of the string with an element prepended

  106. def prependedAll(prefix: String): String

    A copy of the string with another string prepended

  107. def prependedAll[B >: Char](prefix: IterableOnce[B]): immutable.IndexedSeq[B]

    A copy of the string with all elements from a collection prepended

  108. def r: Regex

    You can follow a string with .r, turning it into a Regex.

    You can follow a string with .r, turning it into a Regex. E.g.

    """A\w*""".r is the regular expression for ASCII-only identifiers starting with A.

    """(?<month>\d\d)-(?<day>\d\d)-(?<year>\d\d\d\d)""".r matches dates and provides its subcomponents through groups named "month", "day" and "year".

  109. def reverse: String

    Returns new sequence with elements in reversed order.

    Returns new sequence with elements in reversed order.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  110. def reverseIterator: Iterator[Char]

    An iterator yielding chars in reversed order.

    An iterator yielding chars in reversed order.

    Note: xs.reverseIterator is the same as xs.reverse.iterator but implemented more efficiently.

    returns

    an iterator yielding the chars of this string in reversed order

  111. def size: Int
    Annotations
    @inline()
  112. def sizeCompare(otherSize: Int): Int
  113. def sizeIs: Int
  114. def slice(from: Int, until: Int): String

    Selects an interval of elements.

    Selects an interval of elements. The returned string is made up of all elements x which satisfy the invariant:

    from <= indexOf(x) < until
    from

    the lowest index to include from this string.

    until

    the lowest index to EXCLUDE from this string.

    returns

    a string containing the elements greater than or equal to index from extending up to (but not including) index until of this string.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  115. def sliding(size: Int, step: Int = 1): Iterator[String]

    Groups chars in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)

    Groups chars in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.)

    size

    the number of chars per group

    step

    the distance between the first chars of successive groups

    returns

    An iterator producing strings of size size, except the last element (which may be the only element) will be truncated if there are fewer than size chars remaining to be grouped.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

    See also

    scala.collection.Iterator, method sliding

  116. def sortBy[B](f: (Char) => B)(implicit ord: Ordering[B]): String

    Sorts this string according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

    Sorts this string according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

    The sort is stable. That is, elements that are equal (as determined by ord.compare) appear in the same order in the sorted sequence as in the original.

    B

    the target type of the transformation f, and the type where the ordering ord is defined.

    f

    the transformation function mapping elements to some other domain B.

    ord

    the ordering assumed on domain B.

    returns

    a string consisting of the chars of this string sorted according to the ordering where x < y if ord.lt(f(x), f(y)).

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

    See also

    scala.math.Ordering

  117. def sortWith(lt: (Char, Char) => Boolean): String

    Sorts this string according to a comparison function.

    Sorts this string according to a comparison function.

    The sort is stable. That is, elements that are equal (as determined by lt) appear in the same order in the sorted sequence as in the original.

    lt

    the comparison function which tests whether its first argument precedes its second argument in the desired ordering.

    returns

    a string consisting of the elements of this string sorted according to the comparison function lt.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  118. def sorted[B >: Char](implicit ord: Ordering[B]): String

    Sorts the characters of this string according to an Ordering.

    Sorts the characters of this string according to an Ordering.

    The sort is stable. That is, elements that are equal (as determined by ord.compare) appear in the same order in the sorted sequence as in the original.

    ord

    the ordering to be used to compare elements.

    returns

    a string consisting of the chars of this string sorted according to the ordering ord.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

    See also

    scala.math.Ordering

  119. def span(p: (Char) => Boolean): (String, String)

    Splits this string into a prefix/suffix pair according to a predicate.

    Splits this string into a prefix/suffix pair according to a predicate.

    Note: c span p is equivalent to (but more efficient than) (c takeWhile p, c dropWhile p), provided the evaluation of the predicate p does not cause any side-effects.

    p

    the test predicate

    returns

    a pair consisting of the longest prefix of this string whose chars all satisfy p, and the rest of this string.

  120. def split(separators: Array[Char]): Array[String]
    Annotations
    @throws(clazz = classOf[java.util.regex.PatternSyntaxException])
  121. def split(separator: Char): Array[String]

    Split this string around the separator character

    Split this string around the separator character

    If this string is the empty string, returns an array of strings that contains a single empty string.

    If this string is not the empty string, returns an array containing the substrings terminated by the start of the string, the end of the string or the separator character, excluding empty trailing substrings

    If the separator character is a surrogate character, only split on matching surrogate characters if they are not part of a surrogate pair

    The behaviour follows, and is implemented in terms of String.split(re: String)

    separator

    the character used as a delimiter

    Example:
    1. "a.b".split('.') //returns Array("a", "b")
      
      //splitting the empty string always returns the array with a single
      //empty string
      "".split('.') //returns Array("")
      
      //only trailing empty substrings are removed
      "a.".split('.') //returns Array("a")
      ".a.".split('.') //returns Array("", "a")
      "..a..".split('.') //returns Array("", "", "a")
      
      //all parts are empty and trailing
      ".".split('.') //returns Array()
      "..".split('.') //returns Array()
      
      //surrogate pairs
      val high = 0xD852.toChar
      val low = 0xDF62.toChar
      val highstring = high.toString
      val lowstring = low.toString
      
      //well-formed surrogate pairs are not split
      val highlow = highstring + lowstring
      highlow.split(high) //returns Array(highlow)
      
      //bare surrogate characters are split
      val bare = "_" + highstring + "_"
      bare.split(high) //returns Array("_", "_")
  122. def splitAt(n: Int): (String, String)

    Splits this string into two at a given position.

    Splits this string into two at a given position. Note: c splitAt n is equivalent to (c take n, c drop n).

    n

    the position at which to split.

    returns

    a pair of strings consisting of the first n chars of this string, and the other chars.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  123. def stepper: IntStepper with EfficientSplit

    Stepper can be used with Java 8 Streams.

    Stepper can be used with Java 8 Streams. This method is equivalent to a call to charStepper. See also codePointStepper.

    Annotations
    @inline()
  124. def stripLineEnd: String

    Strip the trailing line separator from this string if there is one.

    Strip the trailing line separator from this string if there is one. The line separator is taken as "\n", "\r", or "\r\n".

  125. def stripMargin: String

    For every line in this string:

    For every line in this string:

    Strip a leading prefix consisting of blanks or control characters followed by | from the line.

  126. def stripMargin(marginChar: Char): String

    For every line in this string:

    For every line in this string:

    Strip a leading prefix consisting of blanks or control characters followed by marginChar from the line.

  127. def stripPrefix(prefix: String): String

    Returns this string with the given prefix stripped.

    Returns this string with the given prefix stripped. If this string does not start with prefix, it is returned unchanged.

  128. def stripSuffix(suffix: String): String

    Returns this string with the given suffix stripped.

    Returns this string with the given suffix stripped. If this string does not end with suffix, it is returned unchanged.

  129. def tail: String

    The rest of the string without its first char.

    The rest of the string without its first char.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  130. def tails: Iterator[String]

    Iterates over the tails of this string.

    Iterates over the tails of this string. The first value will be this string and the final one will be an empty string, with the intervening values the results of successive applications of tail.

    returns

    an iterator over all the tails of this string

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  131. def take(n: Int): String

    A string containing the first n chars of this string.

    A string containing the first n chars of this string.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  132. def takeRight(n: Int): String

    A string containing the last n chars of this string.

    A string containing the last n chars of this string.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  133. def takeWhile(p: (Char) => Boolean): String

    Takes longest prefix of chars that satisfy a predicate.

  134. def toArray[B >: Char](implicit tag: ClassTag[B]): Array[B]
  135. def toBoolean: Boolean

    Exceptions thrown

    java.lang.IllegalArgumentException If the string does not contain a parsable Boolean.

  136. def toBooleanOption: Option[Boolean]

    Try to parse as a Boolean

    Try to parse as a Boolean

    returns

    Some(true) if the string is "true" case insensitive, Some(false) if the string is "false" case insensitive, and None if the string is anything else

    Exceptions thrown

    java.lang.NullPointerException if the string is null

  137. def toByte: Byte

    Parse as a Byte (string must contain only decimal digits and optional leading - or +).

    Parse as a Byte (string must contain only decimal digits and optional leading - or +).

    Exceptions thrown

    java.lang.NumberFormatException If the string does not contain a parsable Byte.

  138. def toByteOption: Option[Byte]

    Try to parse as a Byte

    Try to parse as a Byte

    returns

    Some(value) if the string contains a valid byte value, otherwise None

    Exceptions thrown

    java.lang.NullPointerException if the string is null

  139. def toDouble: Double

    Parse as a Double (surrounding whitespace is removed with a trim).

    Parse as a Double (surrounding whitespace is removed with a trim).

    Exceptions thrown

    java.lang.NullPointerException If the string is null.

    java.lang.NumberFormatException If the string does not contain a parsable Double.

  140. def toDoubleOption: Option[Double]

    Try to parse as a Double

    Try to parse as a Double

    returns

    Some(value) if the string is a parsable Double, None otherwise

    Exceptions thrown

    java.lang.NullPointerException If the string is null

  141. def toFloat: Float

    Parse as a Float (surrounding whitespace is removed with a trim).

    Parse as a Float (surrounding whitespace is removed with a trim).

    Exceptions thrown

    java.lang.NullPointerException If the string is null.

    java.lang.NumberFormatException If the string does not contain a parsable Float.

  142. def toFloatOption: Option[Float]

    Try to parse as a Float

    Try to parse as a Float

    returns

    Some(value) if the string is a parsable Float, None otherwise

    Exceptions thrown

    java.lang.NullPointerException If the string is null

  143. def toInt: Int

    Parse as an Int (string must contain only decimal digits and optional leading - or +).

    Parse as an Int (string must contain only decimal digits and optional leading - or +).

    Exceptions thrown

    java.lang.NumberFormatException If the string does not contain a parsable Int.

  144. def toIntOption: Option[Int]

    Try to parse as an Int

    Try to parse as an Int

    returns

    Some(value) if the string contains a valid Int value, otherwise None

    Exceptions thrown

    java.lang.NullPointerException if the string is null

  145. def toLong: Long

    Parse as a Long (string must contain only decimal digits and optional leading - or +).

    Parse as a Long (string must contain only decimal digits and optional leading - or +).

    Exceptions thrown

    java.lang.NumberFormatException If the string does not contain a parsable Long.

  146. def toLongOption: Option[Long]

    Try to parse as a Long

    Try to parse as a Long

    returns

    Some(value) if the string contains a valid long value, otherwise None

    Exceptions thrown

    java.lang.NullPointerException if the string is null

  147. def toShort: Short

    Parse as a Short (string must contain only decimal digits and optional leading - or +).

    Parse as a Short (string must contain only decimal digits and optional leading - or +).

    Exceptions thrown

    java.lang.NumberFormatException If the string does not contain a parsable Short.

  148. def toShortOption: Option[Short]

    Try to parse as a Short

    Try to parse as a Short

    returns

    Some(value) if the string contains a valid short value, otherwise None

    Exceptions thrown

    java.lang.NullPointerException if the string is null

  149. def toString(): String

    Returns a string representation of the object.

    Returns a string representation of the object.

    The default representation is platform dependent.

    returns

    a string representation of the object.

    Definition Classes
    Any
  150. def updated(index: Int, elem: Char): String

    A copy of this string with one single replaced element.

    A copy of this string with one single replaced element.

    index

    the position of the replacement

    elem

    the replacing element

    returns

    a new string which is a copy of this string with the element at position index replaced by elem.

    Exceptions thrown

    IndexOutOfBoundsException if index does not satisfy 0 <= index < length.

    Note

    This method treats a string as a plain sequence of Char code units and makes no attempt to keep surrogate pairs or codepoint sequences together. The user is responsible for making sure such cases are handled correctly. Failing to do so may result in an invalid Unicode string.

  151. def view: StringView
    Annotations
    @inline()
  152. def withFilter(p: (Char) => Boolean): StringOps.WithFilter

    Creates a non-strict filter of this string.

    Creates a non-strict filter of this string.

    p

    the predicate used to test elements.

    returns

    an object of class stringOps.WithFilter, which supports map, flatMap, foreach, and withFilter operations. All these operations apply to those chars of this string which satisfy the predicate p.

    Note

    the difference between c filter p and c withFilter p is that the former creates a new string, whereas the latter only restricts the domain of subsequent map, flatMap, foreach, and withFilter operations.

Deprecated Value Members

  1. def formatted(fmtstr: String): String

    Returns string formatted according to given format string.

    Returns string formatted according to given format string. Format strings are as for String.format (@see java.lang.String.format).

    Implicit
    This member is added by an implicit conversion from StringOps toStringFormat[StringOps] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @deprecated @inline()
    Deprecated

    (Since version 2.12.16) Use formatString.format(value) instead of value.formatted(formatString), or use the f"" string interpolator. In Java 15 and later, formatted resolves to the new method in String which has reversed parameters.

  2. def lines: Iterator[String]

    Return all lines in this string in an iterator, excluding trailing line end characters; i.e., apply .stripLineEnd to all lines returned by linesWithSeparators.

    Return all lines in this string in an iterator, excluding trailing line end characters; i.e., apply .stripLineEnd to all lines returned by linesWithSeparators.

    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use linesIterator, because JDK 11 adds a lines method on String

  3. def r(groupNames: String*): Regex

    You can follow a string with .r(g1, ... , gn), turning it into a Regex, with group names g1 through gn.

    You can follow a string with .r(g1, ... , gn), turning it into a Regex, with group names g1 through gn.

    """(\d\d)-(\d\d)-(\d\d\d\d)""".r("month", "day", "year") matches dates and provides its subcomponents through groups named "month", "day" and "year".

    groupNames

    The names of the groups in the pattern, in the order they appear.

    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.7) use inline group names like (?<year>X) instead

  4. def replaceAllLiterally(literal: String, replacement: String): String

    Replace all literal occurrences of literal with the literal string replacement.

    Replace all literal occurrences of literal with the literal string replacement. This method is equivalent to java.lang.String#replace(CharSequence,CharSequence).

    literal

    the string which should be replaced everywhere it occurs

    replacement

    the replacement string

    returns

    the resulting string

    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.2) Use s.replace as an exact replacement

  5. def [B](y: B): (StringOps, B)
    Implicit
    This member is added by an implicit conversion from StringOps toArrowAssoc[StringOps] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from AnyVal

Inherited from Any

Inherited by implicit conversion any2stringadd fromStringOps to any2stringadd[StringOps]

Inherited by implicit conversion StringFormat fromStringOps to StringFormat[StringOps]

Inherited by implicit conversion Ensuring fromStringOps to Ensuring[StringOps]

Inherited by implicit conversion ArrowAssoc fromStringOps to ArrowAssoc[StringOps]

Ungrouped