Skip to content

Commit

Permalink
Update task.md (#214)
Browse files Browse the repository at this point in the history
language checked
  • Loading branch information
stephen-hero authored Dec 20, 2023
1 parent f2e6826 commit 5cbc81f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions AlmostDone/multiRowStringsTheory/task.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 1. What are multiline strings?

When working with long strings, it is most convenient to use so-called [multiline strings](https://kotlinlang.org/docs/coding-conventions.html#strings).
When working with long strings, the most convenient approach is to use so-called [multiline strings](https://kotlinlang.org/docs/coding-conventions.html#strings).
Unlike regular strings, they are enclosed in triple quotes:
```kotlin
// A regular string:
Expand All @@ -16,13 +16,13 @@ val multiRowString = """

### 2. The `trimIndent` and `trimMargin` functions

For convenient work with such strings, there are two functions: [`trimIndent`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-indent.html) and [`trimMargin`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html).
`trimIndent` detects the common minimal indent of all the input lines,
removes it from every line, and also removes the first and the last lines
For convenient handling of such strings, Kotlin provides two functions: [`trimIndent`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-indent.html) and [`trimMargin`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html).
`trimIndent` detects the smallest common indentation of all the input lines,
removes it from every line, and also discards the first and the last lines
if they are blank.
`trimMargin` trims leading whitespace characters
followed by `marginPrefix` from every line of a source string and removes
the first and the last lines if they are blank.
followed by `marginPrefix` from every line of a source string and also removes
the first and last lines if they are blank.

For example, check out the following code:
```kotlin
Expand Down Expand Up @@ -59,6 +59,6 @@ Second line of the string
In the first case, the string will have extra indents and margins.
Also, each line in the string has the `*` symbol.
In the second case, the string looks better, but it still has an extra symbol in each line.
The last case looks as the best option.
The last case looks like the best option.

Therefore, when working with multiline strings, such functions are a great help.

0 comments on commit 5cbc81f

Please sign in to comment.