Skip to content

Commit 929f8a6

Browse files
authored
Merge pull request #400 from Peefy/update-str-intepolation-dollar-escape-docs
docs: update str interpolation dollar escape documents
2 parents 2221570 + 75b8313 commit 929f8a6

File tree

8 files changed

+52
-44
lines changed

8 files changed

+52
-44
lines changed

docs/reference/lang/tour.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,19 @@ assert "length length".title() == "Length Length"
360360
assert x.upper() == "LENGTH"
361361
```
362362

363-
There are 2 different ways to format a string: to use the `"{}".format()` built-in function, or to specify the variable between the curly braces and use a `$` mark to tell KCL to extract its value. This is called **string interpolation** in KCL. In following example, both `a` and `b` will be assigned to string `"hello world"`.
363+
There are 2 different ways to format a string: to use the `"{}".format()` built-in function, or to specify the variable between the curly braces and use a `${}` mark to tell KCL to extract its value. This is called **string interpolation** in KCL. In following example, both `a` and `b` will be assigned to string `"hello world"`.
364364

365-
Besides, the variable to serialized can be extracted in special data format, such as YAML or JSON. In this case, a `#yaml` or `#json` can be included within the curly braces.
365+
Besides, the variable to serialized can be extracted in special data format, such as YAML or JSON. In this case, a `#yaml` or `#json` can be included within the curly braces.
366366

367-
Specifically, when the dollar sign `$` itself is needed in a **string interpolation**, it needs to be escaped and use `$$` instead. Or in another way, `+` can be used to concat the dollar sign with the **string interpolation** to avoid that escape. In following example, both `c` and `c2` will be assigned to string `$hello world$`
367+
Note that if we don't want to interpolate variables, we can add the `\` character before `$`.
368368

369369
```python
370370
world = "world"
371-
a = "hello {}".format(world) # "hello world"
372-
b = "hello ${world}" # "hello world"
373-
c = "$$hello ${world}$$" # "$hello world$"
374-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
371+
a = "hello {}".format(world) # "hello world"
372+
b = "hello ${world}" # "hello world"
373+
c1 = "$hello ${world}$" # "$hello world$"
374+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
375+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
375376
376377
myDict = {
377378
"key1" = "value1"

docs/user_docs/support/faq-kcl.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,15 @@ data: value
515515
jsonData: '{"key": "value"}'
516516
```
517517

518-
Note that if we want to use the `$` character alone in the `${}` interpolated string, we need to escape the `$` with `$$`
518+
Note that if we don't want to interpolate variables, we can add the `\` character before `$`.
519519

520520
```python
521521
world = "world"
522-
a = "hello {}".format(world) # "hello world"
523-
b = "hello ${world}" # "hello world"
524-
c = "$$hello ${world}$$" # "$hello world$"
525-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
522+
a = "hello {}".format(world) # "hello world"
523+
b = "hello ${world}" # "hello world"
524+
c1 = "$hello ${world}$" # "$hello world$"
525+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
526+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
526527
```
527528

528529
The output YAML is

i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/lang/tour.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,15 @@ assert x.upper() == "LENGTH"
364364

365365
此外,要序列化的变量可以以特殊的数据格式提取,例如 YAML 或 JSON。在这种情况中,`#yaml` 或 `#json` 可以包含在花括号中。
366366

367-
具体来说,当 `$` 符号本身需要出现在**插值字符串**中,需要使用 `$$` 转义。或者使用 `+` 符号连接 `$` 符号和插值字符串来避免转义。在以下示例中,`c` 和 `c2` 的值都是 `$hello world$`。
367+
注意,如果不想 `${...}` 表示字符串插值 ,我们可以在 `$` 之前添加`\` 字符表示直接以字符串的形式输出 `${...}`。
368368

369369
```python
370370
world = "world"
371-
a = "hello {}".format(world) # "hello world"
372-
b = "hello ${world}" # "hello world"
373-
c = "$$hello ${world}$$" # "$hello world$"
374-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
371+
a = "hello {}".format(world) # "hello world"
372+
b = "hello ${world}" # "hello world"
373+
c1 = "$hello ${world}$" # "$hello world$"
374+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
375+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
375376
376377
myDict = {
377378
"key1" = "value1"

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,15 @@ data: value
517517
jsonData: '{"key": "value"}'
518518
```
519519

520-
注意,如果想在 `${}` 插值字符串中单独使用 `$` 字符,则需要使用 `$$` 对 `$` 进行转义
520+
注意,如果不想 `${...}` 表示字符串插值 ,我们可以在 `$` 之前添加`\` 字符表示直接以字符串的形式输出 `${...}`。
521521

522522
```python
523523
world = "world"
524-
a = "hello {}".format(world) # "hello world"
525-
b = "hello ${world}" # "hello world"
526-
c = "$$hello ${world}$$" # "$hello world$"
527-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
524+
a = "hello {}".format(world) # "hello world"
525+
b = "hello ${world}" # "hello world"
526+
c1 = "$hello ${world}$" # "$hello world$"
527+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
528+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
528529
```
529530

530531
输出 YAML 为:

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/lang/tour.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,15 @@ assert x.upper() == "LENGTH"
364364

365365
此外,要序列化的变量可以以特殊的数据格式提取,例如 YAML 或 JSON。在这种情况中,`#yaml` 或 `#json` 可以包含在花括号中。
366366

367-
具体来说,当 `$` 符号本身需要出现在**插值字符串**中,需要使用 `$$` 转义。或者使用 `+` 符号连接 `$` 符号和插值字符串来避免转义。在以下示例中,`c` 和 `c2` 的值都是 `$hello world$`。
367+
注意,如果不想 `${...}` 表示字符串插值 ,我们可以在 `$` 之前添加`\` 字符表示直接以字符串的形式输出 `${...}`。
368368

369369
```python
370370
world = "world"
371-
a = "hello {}".format(world) # "hello world"
372-
b = "hello ${world}" # "hello world"
373-
c = "$$hello ${world}$$" # "$hello world$"
374-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
371+
a = "hello {}".format(world) # "hello world"
372+
b = "hello ${world}" # "hello world"
373+
c1 = "$hello ${world}$" # "$hello world$"
374+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
375+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
375376
376377
myDict = {
377378
"key1" = "value1"

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/user_docs/support/faq-kcl.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,15 @@ data: value
517517
jsonData: '{"key": "value"}'
518518
```
519519

520-
注意,如果想在 `${}` 插值字符串中单独使用 `$` 字符,则需要使用 `$$` 对 `$` 进行转义
520+
注意,如果不想 `${...}` 表示字符串插值 ,我们可以在 `$` 之前添加`\` 字符表示直接以字符串的形式输出 `${...}`。
521521

522522
```python
523523
world = "world"
524-
a = "hello {}".format(world) # "hello world"
525-
b = "hello ${world}" # "hello world"
526-
c = "$$hello ${world}$$" # "$hello world$"
527-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
524+
a = "hello {}".format(world) # "hello world"
525+
b = "hello ${world}" # "hello world"
526+
c1 = "$hello ${world}$" # "$hello world$"
527+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
528+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
528529
```
529530

530531
输出 YAML 为:

versioned_docs/version-0.9/reference/lang/tour.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,19 @@ assert "length length".title() == "Length Length"
360360
assert x.upper() == "LENGTH"
361361
```
362362

363-
There are 2 different ways to format a string: to use the `"{}".format()` built-in function, or to specify the variable between the curly braces and use a `$` mark to tell KCL to extract its value. This is called **string interpolation** in KCL. In following example, both `a` and `b` will be assigned to string `"hello world"`.
363+
There are 2 different ways to format a string: to use the `"{}".format()` built-in function, or to specify the variable between the curly braces and use a `${}` mark to tell KCL to extract its value. This is called **string interpolation** in KCL. In following example, both `a` and `b` will be assigned to string `"hello world"`.
364364

365-
Besides, the variable to serialized can be extracted in special data format, such as YAML or JSON. In this case, a `#yaml` or `#json` can be included within the curly braces.
365+
Besides, the variable to serialized can be extracted in special data format, such as YAML or JSON. In this case, a `#yaml` or `#json` can be included within the curly braces.
366366

367-
Specifically, when the dollar sign `$` itself is needed in a **string interpolation**, it needs to be escaped and use `$$` instead. Or in another way, `+` can be used to concat the dollar sign with the **string interpolation** to avoid that escape. In following example, both `c` and `c2` will be assigned to string `$hello world$`
367+
Note that if we don't want to interpolate variables, we can add the `\` character before `$`.
368368

369369
```python
370370
world = "world"
371-
a = "hello {}".format(world) # "hello world"
372-
b = "hello ${world}" # "hello world"
373-
c = "$$hello ${world}$$" # "$hello world$"
374-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
371+
a = "hello {}".format(world) # "hello world"
372+
b = "hello ${world}" # "hello world"
373+
c1 = "$hello ${world}$" # "$hello world$"
374+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
375+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
375376
376377
myDict = {
377378
"key1" = "value1"

versioned_docs/version-0.9/user_docs/support/faq-kcl.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,15 @@ data: value
515515
jsonData: '{"key": "value"}'
516516
```
517517

518-
Note that if we want to use the `$` character alone in the `${}` interpolated string, we need to escape the `$` with `$$`
518+
Note that if we don't want to interpolate variables, we can add the `\` character before `$`.
519519

520520
```python
521521
world = "world"
522-
a = "hello {}".format(world) # "hello world"
523-
b = "hello ${world}" # "hello world"
524-
c = "$$hello ${world}$$" # "$hello world$"
525-
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
522+
a = "hello {}".format(world) # "hello world"
523+
b = "hello ${world}" # "hello world"
524+
c1 = "$hello ${world}$" # "$hello world$"
525+
c2 = "$" + "hello ${world}" + "$" # "$hello world$"
526+
c3 = "$" + "hello \${world}" + "$" # "$hello ${world}$"
526527
```
527528

528529
The output YAML is

0 commit comments

Comments
 (0)