Test two objects for inequality.
true if !(this == that), false otherwise.
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.
a hash value consistent with ==
Alias for concat
Alias for concat
Alias for prependedAll
Alias for prependedAll
Alias for prepended
Alias for prepended
Alias for appended
Alias for appended
Alias for appendedAll
Alias for appendedAll
Test two objects for equality. The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).
true if the receiver object is equivalent to the argument; false otherwise.
Appends this string to a string builder using a separator string.
Appends this string to a string builder.
A copy of the string with another string appended
A copy of the string with all elements from a collection appended
Get the char at the specified index.
Cast the receiver object to be of type T0.
Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at runtime, while the expression List(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested type.
the receiver object.
ClassCastException if the receiver object is not an instance of the erasure of type T0.
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).
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.
Steps over code points in this string.
Builds a new collection by applying a partial function to all chars of this String on which the function is defined.
the element type of the returned collection.
the partial function which filters and maps the String.
a new collection resulting from applying the given partial function pf to each char on which it is defined and collecting the results.
Builds a new String by applying a partial function to all chars of this String on which the function is defined.
the partial function which filters and maps the String.
a new String resulting from applying the given partial function pf to each char on which it is defined and collecting the results.
Returns a new string containing the chars from this string followed by the chars from the right hand operand.
the string to append.
a new string which contains all chars of this string followed by all chars of suffix.
Returns a new string containing the chars from this string followed by the chars from the right hand operand.
the collection to append.
a new string which contains all chars of this string followed by all chars of suffix.
Returns a new collection containing the chars from this string followed by the elements from the right hand operand.
the collection to append.
a new collection which contains all chars of this string followed by all elements of suffix.
Tests whether this string contains the given character.
the character to test.
true if this string has an element that is equal (as determined by ==) to elem, false otherwise.
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.
the array to fill.
the starting index.
the maximal number of elements to copy.
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
the array to fill.
the starting index.
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
the array to fill.
Drops longest prefix of chars that satisfy a predicate.
The predicate used to test elements.
the longest suffix of this string whose first element does not satisfy the predicate p.
Selects all chars of this string which do not satisfy a predicate.
Finds the first char of the string satisfying a predicate, if any.
the predicate used to test elements.
an option value containing the first element in the string that satisfies p, or None if none exists.
Builds a new string by applying a function to all chars of this string and using the elements of the resulting strings.
the function to apply to each char.
a new string resulting from applying the given string-valued function f to each char of this string and concatenating the results.
Builds a new collection by applying a function to all chars of this string and using the elements of the resulting collections.
the function to apply to each char.
a new collection resulting from applying the given collection-valued function f to each char of this string and concatenating the results.
Folds the chars of this string using the specified associative binary operator.
a type parameter for the binary operator, a supertype of Char.
a neutral element for the fold operation; may be added to the result an arbitrary number of times, and must not change the result (e.g., Nil for list concatenation, 0 for addition, or 1 for multiplication).
a binary operator that must be associative.
the result of applying the fold operator op between all the chars and z, or z if this string is empty.
Applies a binary operator to a start value and all chars of this string, going left to right.
the result type of the binary operator.
the start value.
the binary operator.
the result of inserting op between consecutive chars of this string, going left to right with the start value z on the left:
op(...op(z, x_1), x_2, ..., x_n)
where x1, ..., xn are the chars of this string. Returns z if this string is empty.
Applies a binary operator to all chars of this string and a start value, going right to left.
the result type of the binary operator.
the start value.
the binary operator.
the result of inserting op between consecutive chars of this string, going right to left with the start value z on the right:
op(x_1, op(x_2, ... op(x_n, z)...))
where x1, ..., xn are the chars of this string. Returns z if this string is empty.
Tests whether a predicate holds for all chars of this string.
true if this string is empty or the given predicate p holds for all chars of this string, otherwise false.
Apply f to each element for its side effects. Note: [U] parameter needed to help scalac's type inference.
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.
the arguments used to instantiating the pattern.
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.
an instance of java.util.Locale
the arguments used to instantiating the pattern.
Returns string formatted according to given format string. Format strings are as for String.format (@see java.lang.String.format).
Returns the runtime class representation of the object.
a class object corresponding to the runtime type of the receiver.
Partitions elements in fixed size strings.
the number of elements per group
An iterator producing strings of size size, except the last will be less than size size if the elements don't divide evenly.
scala.collection.Iterator, method grouped
Selects the first char of this string.
the first char of this string.
NoSuchElementException if the string is empty.
Optionally selects the first char.
the first char of this string if it is nonempty, None if it is empty.
Finds index of the first char satisfying some predicate after or at some start index.
the predicate used to test elements.
the start index
the index >= from of the first element of this string that satisfies the predicate p, or -1, if none exists.
Produces the range of all indices of this string.
a Range value from 0 to one less than the length 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.
an iterator over all the inits of this string
Test whether the dynamic type of the receiver object is T0.
Note that the result of the test is modulo Scala's erasure semantics. Therefore the expression 1.isInstanceOf[String] will return false, while the expression List(1).isInstanceOf[List[String]] will return true. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the specified type.
true if the receiver object is an instance of erasure of type T0; false otherwise.
Selects the last char of this string.
the last char of this string.
NoSuchElementException if the string is empty.
Finds index of the last char satisfying some predicate before or at some end index.
the predicate used to test elements.
the end index
the index <= end of the last element of this string that satisfies the predicate p, or -1, if none exists.
Optionally selects the last char.
the last char of this string if it is nonempty, None if it is empty.
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)
the type of the second element in each eventual pair
the iterable providing the second element of each eventual pair
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.
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.
Return an iterator of all lines embedded in this string, including trailing line separator characters.
The empty string yields an empty iterator.
Builds a new string by applying a function to all chars of this string.
the function to apply to each char.
a new string resulting from applying the given function f to each char of this string and collecting the results.
Builds a new collection by applying a function to all chars of this string.
the function to apply to each char.
a new collection resulting from applying the given function f to each char of this string and collecting the results.
Returns this string
Displays all elements of this string in a string using a separator string.
the separator string.
In the resulting string the chars of this string are separated by the string sep.
Displays all elements of this string in a string using start, end, and separator strings.
the starting string.
the separator string.
the ending string.
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.
Tests whether the string is not empty.
Returns a string with a char appended until a given target length is reached.
the target length
the padding value
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.
Returns a collection with an element appended until a given target length is reached.
the target length
the padding value
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.
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")
the 'split function' mapping the elements of this string to an scala.util.Either
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.
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.
the index of the first replaced char
the replacement string
the number of chars to drop in the original string
a new string consisting of all chars of this string except that replaced chars starting from from are replaced by other.
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.
the index of the first replaced char
the replacement string
the number of chars to drop in the original string
a new string consisting of all chars of this string except that replaced chars starting from from are replaced by other.
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.
the index of the first replaced char
the replacement collection
the number of chars to drop in the original string
a new collection consisting of all chars of this string except that replaced chars starting from from are replaced by other.
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".
The names of the groups in the pattern, in the order they appear.
You can follow a string with .r, turning it into a Regex. E.g.
"""A\w*""".r is the regular expression for identifiers starting with A.
Replace all literal occurrences of literal with the literal string replacement. This method is equivalent to java.lang.String#replace.
the string which should be replaced everywhere it occurs
the replacement string
the resulting string
An iterator yielding chars in reversed order.
Note: xs.reverseIterator is the same as xs.reverse.iterator but implemented more efficiently.
an iterator yielding the chars of this string in reversed order
Selects an interval of elements. The returned string is made up of all elements x which satisfy the invariant:
from <= indexOf(x) < until
the lowest index to include from this string.
the lowest index to EXCLUDE from this string.
a string containing the elements greater than or equal to index from extending up to (but not including) index until of this string.
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.
the test predicate
a pair consisting of the longest prefix of this string whose chars all satisfy p, and the rest of this string.
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)
the character used as a delimiter
"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("_", "_")
Splits this string into two at a given position. Note: c splitAt n is equivalent to (c take n, c drop n).
the position at which to split.
a pair of strings consisting of the first n chars of this string, and the other chars.
Stepper can be used with Java 8 Streams. This method is equivalent to a call to charStepper. See also codePointStepper.
Strip the trailing line separator from this string if there is one. The line separator is taken as "\n", "\r", or "\r\n".
For every line in this string:
Strip a leading prefix consisting of blanks or control characters followed by | from the line.
For every line in this string:
Strip a leading prefix consisting of blanks or control characters followed by marginChar from the line.
Returns this string with the given prefix stripped. If this string does not start with prefix, it is returned unchanged.
Returns this string with the given suffix stripped. If this string does not end with suffix, it is returned unchanged.
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.
an iterator over all the tails of this string
java.lang.IllegalArgumentException If the string does not contain a parsable Boolean.
Try to parse as a Boolean
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
java.lang.NullPointerException if the string is null
Parse as a Byte (string must contain only decimal digits and optional leading - or +).
java.lang.NumberFormatException If the string does not contain a parsable Byte.
Try to parse as a Byte
Some(value) if the string contains a valid byte value, otherwise None
java.lang.NullPointerException if the string is null
Parse as a Double (surrounding whitespace is removed with a trim).
java.lang.NullPointerException If the string is null.
java.lang.NumberFormatException If the string does not contain a parsable Double.
Try to parse as a Double
Some(value) if the string is a parsable Double, None otherwise
java.lang.NullPointerException If the string is null
Parse as a Float (surrounding whitespace is removed with a trim).
java.lang.NullPointerException If the string is null.
java.lang.NumberFormatException If the string does not contain a parsable Float.
Try to parse as a Float
Some(value) if the string is a parsable Float, None otherwise
java.lang.NullPointerException If the string is null
Parse as an Int (string must contain only decimal digits and optional leading - or +).
java.lang.NumberFormatException If the string does not contain a parsable Int.
Try to parse as an Int
Some(value) if the string contains a valid Int value, otherwise None
java.lang.NullPointerException if the string is null
Parse as a Long (string must contain only decimal digits and optional leading - or +).
java.lang.NumberFormatException If the string does not contain a parsable Long.
Try to parse as a Long
Some(value) if the string contains a valid long value, otherwise None
java.lang.NullPointerException if the string is null
Parse as a Short (string must contain only decimal digits and optional leading - or +).
java.lang.NumberFormatException If the string does not contain a parsable Short.
Try to parse as a Short
Some(value) if the string contains a valid short value, otherwise None
java.lang.NullPointerException if the string is null
Returns a string representation of the object.
The default representation is platform dependent.
a string representation of the object.
A copy of this string with one single replaced element.
the position of the replacement
the replacing element
a new string which is a copy of this string with the element at position index replaced by elem.
IndexOutOfBoundsException if index does not satisfy 0 <= index < length.
Creates a non-strict filter of this string.
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.
the predicate used to test elements.
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.
© 2002-2019 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://www.scala-lang.org/api/2.13.0/scala/collection/StringOps.html