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/StringContext/s

s

scala.StringContext.s
objects

Attributes

Source
StringContext.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Self type

Members list

Value members

Concrete methods

The simple string matcher.

The simple string matcher.

Attempts to match the input string to the given interpolated patterns via a naive globbing, that is the reverse of the simple interpolator.

Here is an example usage:

val s"Hello, $name" = "Hello, James"println(name)  // "James"

In this example, the string "James" ends up matching the location where the pattern$name is positioned, and thus ends up bound to that variable.

Multiple matches are supported:

val s"$greeting, $name" = "Hello, James"println(greeting)  // "Hello"println(name)  // "James"

And thes matcher can match an arbitrary pattern within the${} block, for example:

val TimeSplitter = "([0-9]+)[.:]([0-9]+)".rval s"The time is ${TimeSplitter(hours, mins)}" = "The time is 10.50"println(hours) // 10println(mins) // 50

Here, we use theTimeSplitter regex within thes matcher, further splitting the matched string "10.50" into its constituent parts

Attributes

Source
StringContext.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp