Skip to content

Commit

Permalink
update: rename raw strings to multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
koshachy committed Aug 2, 2023
1 parent 1865360 commit b19acb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/topics/jvm/java-to-kotlin-idioms-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ System.out.println("Anonymized input: '" + replacementResult + "'");

In Kotlin, you use the [Regex](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/) class
that simplifies working with regular expressions.
Additionally, use [raw strings](strings.md#string-literals) to simplify a regex pattern
Additionally, use [multiline strings](strings.md#multiline-strings) to simplify a regex pattern
by reducing the count of backslashes:

```kotlin
fun main() {
//sampleStart
// Kotlin
val regex = Regex("""\w*\d+\w*""") // raw string
val regex = Regex("""\w*\d+\w*""") // multiline string
val input = "login: Pokemon5, password: 1q2w3e4r5t"
val replacementResult = regex.replace(input, replacement = "xxx")
println("Initial input: '$input'")
Expand Down
14 changes: 7 additions & 7 deletions docs/topics/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ println(s + "def")
```
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}

> In most cases using [string templates](#string-templates) or [raw strings](#raw-strings) is preferable to string concatenation.
> In most cases using [string templates](#string-templates) or [multiline strings](#multiline-strings) is preferable to string concatenation.
>
{type="note"}

Expand All @@ -58,7 +58,7 @@ println(s + "def")
Kotlin has two types of string literals:

* [Escaped strings](#escaped-strings)
* [Raw strings](#raw-strings)
* [Multiline strings](#multiline-strings)

### Escaped strings

Expand All @@ -72,9 +72,9 @@ val s = "Hello, world!\n"
Escaping is done in the conventional way, with a backslash (`\`).
See [Characters](characters.md) page for the list of supported escape sequences.

### Raw strings
### Multiline strings

_Raw strings_ can contain newlines and arbitrary text. It is delimited by a triple quote (`"""`), contains no escaping and can contain newlines and any other characters:
_Multiline strings_ can contain newlines and arbitrary text. It is delimited by a triple quote (`"""`), contains no escaping and can contain newlines and any other characters:

```kotlin
val text = """
Expand All @@ -83,7 +83,7 @@ val text = """
"""
```

To remove leading whitespace from raw strings, use the [`trimMargin()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html) function:
To remove leading whitespace from multiline strings, use the [`trimMargin()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html) function:

```kotlin
val text = """
Expand Down Expand Up @@ -123,8 +123,8 @@ fun main() {
```
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}

You can use templates both in raw and escaped strings.
To insert the dollar sign `$` in a raw string (which doesn't support backslash escaping) before any symbol,
You can use templates both in multiline and escaped strings.
To insert the dollar sign `$` in a multiline string (which doesn't support backslash escaping) before any symbol,
which is allowed as a beginning of an [identifier](https://kotlinlang.org/docs/reference/grammar.html#identifiers),
use the following syntax:

Expand Down

0 comments on commit b19acb3

Please sign in to comment.