Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.collection/StringOps

StringOps

scala.collection.StringOps
See theStringOps companion object
finalclassStringOps(s:String) extendsAnyVal

Provides extension methods for strings.

Some of these methods treat strings as a plain collection ofChars 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.

Attributes

Companion
object
Source
StringOps.scala
Graph
Supertypes
classAnyVal
traitMatchable
classAny

Members list

Value members

Concrete methods

def*(n:Int):String

Return the current string concatenatedn times.

Return the current string concatenatedn times.

Attributes

Source
StringOps.scala
def++[B >:Char](suffix:Iterable[B]):IndexedSeq[B]

Alias forconcat

Alias forconcat

Attributes

Source
StringOps.scala

Alias forconcat

Alias forconcat

Attributes

Source
StringOps.scala

Alias forconcat

Alias forconcat

Attributes

Source
StringOps.scala
def++:[B >:Char](prefix:IterableOnce[B]):IndexedSeq[B]

Alias forprependedAll

Alias forprependedAll

Attributes

Source
StringOps.scala
def++:(prefix:String):String

Alias forprependedAll

Alias forprependedAll

Attributes

Source
StringOps.scala
def+:[B >:Char](elem:B):IndexedSeq[B]

Alias forprepended

Alias forprepended

Attributes

Source
StringOps.scala
def+:(c:Char):String

Alias forprepended

Alias forprepended

Attributes

Source
StringOps.scala
def:+[B >:Char](elem:B):IndexedSeq[B]

Alias forappended

Alias forappended

Attributes

Source
StringOps.scala
def:+(c:Char):String

Alias forappended

Alias forappended

Attributes

Source
StringOps.scala
def:++[B >:Char](suffix:IterableOnce[B]):IndexedSeq[B]

Alias forappendedAll

Alias forappendedAll

Attributes

Source
StringOps.scala
def:++(suffix:String):String

Alias forappendedAll

Alias forappendedAll

Attributes

Source
StringOps.scala
def<(that:String):Boolean

Returns true ifthis is less thanthat

Returns true ifthis is less thanthat

Attributes

Source
StringOps.scala
def<=(that:String):Boolean

Returns true ifthis is less than or equal tothat.

Returns true ifthis is less than or equal tothat.

Attributes

Source
StringOps.scala
def>(that:String):Boolean

Returns true ifthis is greater thanthat.

Returns true ifthis is greater thanthat.

Attributes

Source
StringOps.scala
def>=(that:String):Boolean

Returns true ifthis is greater than or equal tothat.

Returns true ifthis is greater than or equal tothat.

Attributes

Source
StringOps.scala
finaldefaddString(b:StringBuilder): b.type

Appends this string to a string builder.

Appends this string to a string builder.

Attributes

Source
StringOps.scala
finaldefaddString(b: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.

Attributes

Source
StringOps.scala
finaldefaddString(b:StringBuilder,start:String,sep:String,end:String): b.type

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

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

Attributes

Source
StringOps.scala
defappended[B >:Char](elem:B):IndexedSeq[B]

A copy of the string with an element appended

A copy of the string with an element appended

Attributes

Source
StringOps.scala

A copy of the string with an element appended

A copy of the string with an element appended

Attributes

Source
StringOps.scala
defappendedAll[B >:Char](suffix:IterableOnce[B]):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

Attributes

Source
StringOps.scala

A copy of the string with another string appended

A copy of the string with another string appended

Attributes

Source
StringOps.scala
defapply(i:Int):Char

Get the char at the specified index.

Get the char at the specified index.

Attributes

Source
StringOps.scala

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

Attributes

Source
StringOps.scala

Steps over characters in this string.

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

Attributes

Source
StringOps.scala

Steps over code points in this string.

Steps over code points in this string.

Attributes

Source
StringOps.scala

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.

Value parameters

pf

the partial function which filters and maps the String.

Attributes

Returns

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

Source
StringOps.scala

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.

Type parameters

B

the element type of the returned collection.

Value parameters

pf

the partial function which filters and maps the String.

Attributes

Returns

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

Source
StringOps.scala

Iterates over combinations of elements.

Iterates over combinations of elements.

Acombination of lengthn is a sequence ofn elements selected in order of their first index in this sequence.

For example,"xyx" has two combinations of length 2. Thex 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 thex elements.

As a further illustration,"xyxx" has three different ways to generate"xy" because there are three elementsx 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 firstx 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 eachx element is also arbitrary.

Attributes

Returns

An Iterator which traverses the n-element combinations 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.

Example

"abbbc".combinations(2).foreach(println)// ab// ac// bb// bc"bab".combinations(2).foreach(println)// bb// ba
Source
StringOps.scala
defcompare(that:String):Int

Attributes

Source
StringOps.scala
defconcat[B >:Char](suffix:IterableOnce[B]):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.

Value parameters

suffix

the collection to append.

Attributes

Returns

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

Source
StringOps.scala

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.

Value parameters

suffix

the collection to append.

Attributes

Returns

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

Source
StringOps.scala
defconcat(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.

Value parameters

suffix

the string to append.

Attributes

Returns

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

Source
StringOps.scala

Tests whether this string contains the given character.

Tests whether this string contains the given character.

Value parameters

elem

the character to test.

Attributes

Returns

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

Source
StringOps.scala

Copy chars of this string to an array.

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

Value parameters

xs

the array to fill.

Attributes

Source
StringOps.scala
defcopyToArray(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 arrayxs starting at indexstart. Copying will stop once either the entire string has been copied or the end of the array is reached

Value parameters

start

the starting index.

xs

the array to fill.

Attributes

Source
StringOps.scala
defcopyToArray(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 arrayxs starting at indexstart with at mostlen chars. Copying will stop once either the entire string has been copied, or the end of the array is reached orlen chars have been copied.

Value parameters

len

the maximal number of elements to copy.

start

the starting index.

xs

the array to fill.

Attributes

Source
StringOps.scala

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

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

Attributes

Source
StringOps.scala
defdiff[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.

Value parameters

that

the sequence of chars to remove

Attributes

Returns

a new string which contains all chars of this string except some of occurrences of elements that also appear inthat. If an element valuex appearsn times inthat, then the firstn occurrences ofx 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.

Source
StringOps.scala

Selects all distinct chars of this string ignoring the duplicates.

Selects all distinct chars of this string ignoring the duplicates.

Attributes

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.

Source
StringOps.scala
defdistinctBy[B](f:Char=>B):String

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

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

Type parameters

B

the type of the elements after being transformed byf

Value parameters

f

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

Attributes

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.

Source
StringOps.scala

The rest of the string without itsn first chars.

The rest of the string without itsn first chars.

Attributes

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.

Source
StringOps.scala

The rest of the string without itsn last chars.

The rest of the string without itsn last chars.

Attributes

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.

Source
StringOps.scala

Drops longest prefix of chars that satisfy a predicate.

Drops longest prefix of chars that satisfy a predicate.

Value parameters

p

The predicate used to test elements.

Attributes

Returns

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

Source
StringOps.scala

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

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

Attributes

Source
StringOps.scala

Selects all chars of this string which satisfy a predicate.

Selects all chars of this string which satisfy a predicate.

Attributes

Source
StringOps.scala

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

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

Attributes

Source
StringOps.scala

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

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

Value parameters

p

the predicate used to test elements.

Attributes

Returns

an option value containing the first element in the string that satisfiesp, orNone if none exists.

Source
StringOps.scala

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.

Value parameters

f

the function to apply to each char.

Attributes

Returns

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

Source
StringOps.scala

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.

Value parameters

f

the function to apply to each char.

Attributes

Returns

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

Source
StringOps.scala
deffold[A1 >:Char](z:A1)(op: (A1,A1)=>A1):A1

Alias forfoldLeft.

Alias forfoldLeft.

The type parameter is more restrictive than forfoldLeft to be consistent withIterableOnceOps.fold.

Type parameters

A1

The type parameter for the binary operator, a supertype ofChar.

Value parameters

op

A binary operator.

z

An initial value.

Attributes

Returns

The result of applyingop toz and all chars in this string, going left to right. Returnsz if this string is empty.

Source
StringOps.scala
deffoldLeft[B](z:B)(op: (B,Char)=>B):B

Applies the given binary operatorop to the given initial valuez and all chars in this string, going left to right.

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

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

Type parameters

B

The result type of the binary operator.

Value parameters

op

A binary operator.

z

An initial value.

Attributes

Returns

The result of applyingop toz and all chars in this string, going left to right. Returnsz if this string is empty.

Source
StringOps.scala
deffoldRight[B](z:B)(op: (Char,B)=>B):B

Applies the given binary operatorop to all chars in this string and the given initial valuez, going right to left.

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

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

Type parameters

B

The result type of the binary operator.

Value parameters

op

A binary operator.

z

An initial value.

Attributes

Returns

The result of applyingop to all chars in this string andz, going right to left. Returnsz if this string is empty.

Source
StringOps.scala

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

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

Value parameters

p

the predicate used to test elements.

Attributes

Returns

true if this string is empty or the given predicatep holds for all chars of this string, otherwisefalse.

Source
StringOps.scala
defforeach[U](f:Char=>U):Unit

Applyf to each element for its side effects.

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

Attributes

Source
StringOps.scala
defformat(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 injava.util.Formatter, with the addition that classes deriving fromScalaNumber (such asscala.BigInt andscala.BigDecimal) are unwrapped to pass a type whichFormatter understands.

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

Value parameters

args

the arguments used to instantiating the pattern.

Attributes

Throws

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

Source
StringOps.scala

Likeformat(args*) but takes an initialLocale parameter which influences formatting as injava.lang.String's format.

Likeformat(args*) but takes an initialLocale parameter which influences formatting as injava.lang.String's format.

The interpretation of the formatting patterns is described injava.util.Formatter, with the addition that classes deriving fromScalaNumber (such asscala.BigInt andscala.BigDecimal) are unwrapped to pass a type whichFormatter understands.

Value parameters

args

the arguments used to instantiating the pattern.

l

an instance ofjava.util.Locale

Attributes

Throws

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

Source
StringOps.scala
defgroupBy[K](f:Char=>K):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.

Type parameters

K

the type of keys returned by the discriminator function.

Value parameters

f

the discriminator function.

Attributes

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 keyk is bound to a string of those elementsx for whichf(x) equalsk.

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.

Source
StringOps.scala

Partitions elements in fixed size strings.

Partitions elements in fixed size strings.

Value parameters

size

the number of elements per group

Attributes

Returns

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

See also
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.

Source
StringOps.scala

Selects the first char of this string.

Selects the first char of this string.

Attributes

Returns

the first char of this string.

Throws

NoSuchElementExceptionif the string is empty.

Source
StringOps.scala

Optionally selects the first char.

Optionally selects the first char.

Attributes

Returns

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

Source
StringOps.scala
defindexWhere(p:Char=>Boolean,from:Int = ...):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.

Value parameters

from

the start index

p

the predicate used to test elements.

Attributes

Returns

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

Source
StringOps.scala

Produces the range of all indices of this string.

Produces the range of all indices of this string.

Attributes

Returns

aRange value from0 to one less than the length of this string.

Source
StringOps.scala

The initial part of the string without its last char.

The initial part of the string without its last char.

Attributes

Throws

UnsupportedOperationExceptionif the string is empty.

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.

Source
StringOps.scala

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

Attributes

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.

Source
StringOps.scala
defintersect[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.

Value parameters

that

the sequence of chars to intersect with.

Attributes

Returns

a new string which contains all chars of this string which also appear inthat. If an element valuex appearsn times inthat, then the firstn occurrences ofx 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.

Source
StringOps.scala

Iterator can be used only once

Iterator can be used only once

Attributes

Source
StringOps.scala

Attributes

Source
StringOps.scala

Selects the last char of this string.

Selects the last char of this string.

Attributes

Returns

the last char of this string.

Throws

NoSuchElementExceptionif the string is empty.

Source
StringOps.scala
deflastIndexWhere(p:Char=>Boolean,end:Int = ...):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.

Value parameters

end

the end index

p

the predicate used to test elements.

Attributes

Returns

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

Source
StringOps.scala

Optionally selects the last char.

Optionally selects the last char.

Attributes

Returns

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

Source
StringOps.scala
deflazyZip[B](that:Iterable[B]):LazyZip2[Char,B,String]

Analogous tozip except that the elements in each collection are not consumed until a strict operation is invoked on the returnedLazyZip2 decorator.

Analogous tozip except that the elements in each collection are not consumed until a strict operation is invoked on the returnedLazyZip2 decorator.

Calls tolazyZip 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)

Type parameters

B

the type of the second element in each eventual pair

Value parameters

that

the iterable providing the second element of each eventual pair

Attributes

Returns

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

Source
StringOps.scala

Attributes

Source
StringOps.scala

Attributes

Source
StringOps.scala

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.

Attributes

Source
StringOps.scala

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.

Attributes

Source
StringOps.scala
defmap[B](f:Char=>B):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.

Value parameters

f

the function to apply to each char.

Attributes

Returns

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

Source
StringOps.scala

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.

Value parameters

f

the function to apply to each char.

Attributes

Returns

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

Source
StringOps.scala
finaldefmkString(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.

Value parameters

end

the ending string.

sep

the separator string.

start

the starting string.

Attributes

Returns

The resulting string begins with the stringstart and ends with the stringend. Inside, the string chars of this string are separated by the stringsep.

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.

Source
StringOps.scala
finaldefmkString(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.

Value parameters

sep

the separator string.

Attributes

Returns

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

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.

Source
StringOps.scala

Returns this string

Returns this string

Attributes

Source
StringOps.scala

Tests whether the string is not empty.

Tests whether the string is not empty.

Attributes

Source
StringOps.scala
defpadTo[B >:Char](len:Int,elem:B):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.

Value parameters

elem

the padding value

len

the target length

Attributes

Returns

a collection consisting of this string followed by the minimal number of occurrences ofelem so that the resulting collection has a length of at leastlen.

Source
StringOps.scala
defpadTo(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.

Value parameters

elem

the padding value

len

the target length

Attributes

Returns

a string consisting of this string followed by the minimal number of occurrences ofelem so that the resulting string has a length of at leastlen.

Source
StringOps.scala

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

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

Attributes

Source
StringOps.scala

Applies a functionf to each character of the string and returns a pair of strings: the first one made of those characters returned byf that were wrapped inscala.util.Left, and the second one made of those wrapped inscala.util.Right.

Applies a functionf to each character of the string and returns a pair of strings: the first one made of those characters returned byf that were wrapped inscala.util.Left, and the second one made of those wrapped inscala.util.Right.

Example:

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

Value parameters

f

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

Attributes

Returns

a pair of strings: the first one made of those characters returned byf that were wrapped inscala.util.Left, and the second one made of those wrapped inscala.util.Right.

Source
StringOps.scala
defpatch[B >:Char](from:Int,other:IterableOnce[B],replaced:Int):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.

Value parameters

from

the index of the first replaced char

other

the replacement collection

replaced

the number of chars to drop in the original string

Attributes

Returns

a new collection consisting of all chars of this string except thatreplaced chars starting fromfrom are replaced byother.

Source
StringOps.scala
defpatch(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.

Value parameters

from

the index of the first replaced char

other

the replacement string

replaced

the number of chars to drop in the original string

Attributes

Returns

a new string consisting of all chars of this string except thatreplaced chars starting fromfrom are replaced byother.

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.

Source
StringOps.scala
defpatch(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.

Value parameters

from

the index of the first replaced char

other

the replacement string

replaced

the number of chars to drop in the original string

Attributes

Returns

a new string consisting of all chars of this string except thatreplaced chars starting fromfrom are replaced byother.

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.

Source
StringOps.scala

Iterates over distinct permutations of elements.

Iterates over distinct permutations of elements.

Attributes

Returns

An Iterator which traverses the distinct permutations 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.

Example

"abb".permutations.foreach(println)// abb// bab// bba
Source
StringOps.scala
defprepended[B >:Char](elem:B):IndexedSeq[B]

A copy of the string with an element prepended

A copy of the string with an element prepended

Attributes

Source
StringOps.scala

A copy of the string with an char prepended

A copy of the string with an char prepended

Attributes

Source
StringOps.scala

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

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

Attributes

Source
StringOps.scala

A copy of the string with another string prepended

A copy of the string with another string prepended

Attributes

Source
StringOps.scala
defr:Regex

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

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

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

"""(?<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".

Attributes

Source
StringOps.scala

Returns new sequence with elements in reversed order.

Returns new sequence with elements in reversed order.

Attributes

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.

Source
StringOps.scala

An iterator yielding chars in reversed order.

An iterator yielding chars in reversed order.

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

Attributes

Returns

an iterator yielding the chars of this string in reversed order

Source
StringOps.scala

Attributes

Source
StringOps.scala
defsizeCompare(otherSize:Int):Int

Attributes

Source
StringOps.scala

Attributes

Source
StringOps.scala
defslice(from:Int,until:Int):String

Selects an interval of elements.

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

from <= indexOf(x) < until

Value parameters

from

the lowest index to include from this string.

until

the lowest index to EXCLUDE from this string.

Attributes

Returns

a string containing the elements greater than or equal to indexfrom extending up to (but not including) indexuntil 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.

Source
StringOps.scala
defsliding(size:Int,step:Int = ...):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.)

Value parameters

size

the number of chars per group

step

the distance between the first chars of successive groups

Attributes

Returns

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

See also
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.

Source
StringOps.scala
defsortBy[B](f:Char=>B)(implicitord: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 byord.compare) appear in the same order in the sorted sequence as in the original.

Type parameters

B

the target type of the transformationf, and the type where the orderingord is defined.

Value parameters

f

the transformation function mapping elements to some other domainB.

ord

the ordering assumed on domainB.

Attributes

Returns

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

See also
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.

Source
StringOps.scala

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 bylt) appear in the same order in the sorted sequence as in the original.

Value parameters

lt

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

Attributes

Returns

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

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.

Source
StringOps.scala
defsorted[B >:Char](implicitord: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 byord.compare) appear in the same order in the sorted sequence as in the original.

Value parameters

ord

the ordering to be used to compare elements.

Attributes

Returns

a string consisting of the chars of this string sorted according to the orderingord.

See also
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.

Source
StringOps.scala

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 predicatep does not cause any side-effects.

Value parameters

p

the test predicate

Attributes

Returns

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

Source
StringOps.scala
defsplit(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 ofString.split(re: String)

Value parameters

separator

the character used as a delimiter

Attributes

Example

"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 pairsval high = 0xD852.toCharval low = 0xDF62.toCharval highstring = high.toStringval lowstring = low.toString//well-formed surrogate pairs are not splitval highlow = highstring + lowstringhighlow.split(high) //returns Array(highlow)//bare surrogate characters are splitval bare = "_" + highstring + "_"bare.split(high) //returns Array("_", "_")
Source
StringOps.scala
defsplit(separators:Array[Char]):Array[String]

Attributes

Source
StringOps.scala

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

Value parameters

n

the position at which to split.

Attributes

Returns

a pair of strings consisting of the firstn 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.

Source
StringOps.scala

Stepper can be used with Java 8 Streams.

Stepper can be used with Java 8 Streams. This method is equivalent to a call tocharStepper. See alsocodePointStepper.

Attributes

Source
StringOps.scala

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

Attributes

Source
StringOps.scala
defstripMargin(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 bymarginChar from the line.

Attributes

Source
StringOps.scala

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.

Attributes

Source
StringOps.scala

Returns this string with the givenprefix stripped.

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

Attributes

Source
StringOps.scala

Returns this string with the givensuffix stripped.

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

Attributes

Source
StringOps.scala

The rest of the string without its first char.

The rest of the string without its first char.

Attributes

Throws

UnsupportedOperationExceptionif the string is empty.

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.

Source
StringOps.scala

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

Attributes

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.

Source
StringOps.scala

A string containing the firstn chars of this string.

A string containing the firstn chars of this string.

Attributes

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.

Source
StringOps.scala

A string containing the lastn chars of this string.

A string containing the lastn chars of this string.

Attributes

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.

Source
StringOps.scala

Takes longest prefix of chars that satisfy a predicate.

Takes longest prefix of chars that satisfy a predicate.

Attributes

Source
StringOps.scala
deftoArray[B >:Char](implicittag:ClassTag[B]):Array[B]

Attributes

Source
StringOps.scala

Attributes

Throws

java.lang.IllegalArgumentExceptionIf the string does not contain a parsableBoolean.

Source
StringOps.scala

Try to parse as aBoolean

Try to parse as aBoolean

Attributes

Returns

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

Throws

java.lang.NullPointerExceptionif the string isnull

Source
StringOps.scala

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

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

Attributes

Throws

java.lang.NumberFormatExceptionIf the string does not contain a parsableByte.

Source
StringOps.scala

Try to parse as aByte

Try to parse as aByte

Attributes

Returns

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

Throws

java.lang.NullPointerExceptionif the string isnull

Source
StringOps.scala

Parse as aDouble (surrounding whitespace is removed with atrim).

Parse as aDouble (surrounding whitespace is removed with atrim).

Attributes

Throws

java.lang.NullPointerExceptionIf the string is null.

java.lang.NumberFormatExceptionIf the string does not contain a parsableDouble.

Source
StringOps.scala

Try to parse as aDouble

Try to parse as aDouble

Attributes

Returns

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

Throws

java.lang.NullPointerException If the string is null

Source
StringOps.scala

Parse as aFloat (surrounding whitespace is removed with atrim).

Parse as aFloat (surrounding whitespace is removed with atrim).

Attributes

Throws

java.lang.NullPointerExceptionIf the string is null.

java.lang.NumberFormatExceptionIf the string does not contain a parsableFloat.

Source
StringOps.scala

Try to parse as aFloat

Try to parse as aFloat

Attributes

Returns

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

Throws

java.lang.NullPointerException If the string is null

Source
StringOps.scala

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

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

Attributes

Throws

java.lang.NumberFormatExceptionIf the string does not contain a parsableInt.

Source
StringOps.scala

Try to parse as anInt

Try to parse as anInt

Attributes

Returns

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

Throws

java.lang.NullPointerExceptionif the string isnull

Source
StringOps.scala

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

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

Attributes

Throws

java.lang.NumberFormatExceptionIf the string does not contain a parsableLong.

Source
StringOps.scala

Try to parse as aLong

Try to parse as aLong

Attributes

Returns

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

Throws

java.lang.NullPointerExceptionif the string isnull

Source
StringOps.scala

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

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

Attributes

Throws

java.lang.NumberFormatExceptionIf the string does not contain a parsableShort.

Source
StringOps.scala

Try to parse as aShort

Try to parse as aShort

Attributes

Returns

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

Throws

java.lang.NullPointerExceptionif the string isnull

Source
StringOps.scala
defupdated(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.

Value parameters

elem

the replacing element

index

the position of the replacement

Attributes

Returns

a new string which is a copy of this string with the element at positionindex replaced byelem.

Throws

IndexOutOfBoundsExceptionifindex does not satisfy0 <= 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.

Source
StringOps.scala

Attributes

Source
StringOps.scala

Creates a non-strict filter of this string.

Creates a non-strict filter of this string.

Value parameters

p

the predicate used to test elements.

Attributes

Returns

an object of classstringOps.WithFilter, which supportsmap,flatMap,foreach, andwithFilter operations. All these operations apply to those chars of this string which satisfy the predicatep.

Note

the difference betweenc filter p andc withFilter p is that the former creates a new string, whereas the latter only restricts the domain of subsequentmap,flatMap,foreach, andwithFilter operations.

Source
StringOps.scala

Deprecated methods

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

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

Attributes

Deprecated
[Since version 2.13.0]Use `linesIterator`, because JDK 11 adds a `lines` method on String
Source
StringOps.scala
defr(groupNames:String*):Regex

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

You can follow a string with.r(g1, ... , gn), turning it into aRegex, 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".

Value parameters

groupNames

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

Attributes

Deprecated
[Since version 2.13.7]use inline group names like (?<year>X) instead
Source
StringOps.scala
defreplaceAllLiterally(literal:String,replacement:String):String

Replace all literal occurrences ofliteral with the literal stringreplacement.

Replace all literal occurrences ofliteral with the literal stringreplacement. This method is equivalent tojava.lang.String#replace.

Value parameters

literal

the string which should be replaced everywhere it occurs

replacement

the replacement string

Attributes

Returns

the resulting string

Deprecated
[Since version 2.13.2]Use `s.replace` as an exact replacement
Source
StringOps.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp