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 task.md #214

Merged
merged 1 commit into from
Dec 20, 2023
Merged
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
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.
Loading