Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: rename raw strings to multiline #3722

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading