A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://scala-lang.org/api/3.x/scala/StringContext$s$.html below:

s

scala.StringContext.s

Members list

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 the s matcher can match an arbitrary pattern within the ${} block, for example:

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

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

Attributes
Source
StringContext.scala

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4