如何在文本里面写引号:
前任: child: Text ("One fine day I woke up from" Bad Mood "was Monday"),
Container(
color: Colors.white,
height: 50,
width: 390,
margin: EdgeInsets.only(left: 15.0, top: 15.0, right: 15.0, bottom: 5.0 ),
alignment: Alignment.topRight,
child: Text ("2 ?? ????? ????? ??? ?? ??? ???? ???? ???? ??????? ??? ????? "??? ????".", textDirection: TextDirection.rtl,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 25.0,
fontFamily: 'Poppins',
fontWeight: FontWeight.w600,
color: Colors.black,
),),
),
Run Code Online (Sandbox Code Playgroud)
child: Text ('One fine day I woke up from" Bad Mood "was Monday'),
Run Code Online (Sandbox Code Playgroud)
Dart 字符串文字有多种方法可以在字符串中包含引号。
Dart 字符串文字可以通过三种方式变化:
') 或双引号 ( ")。r)或内插的(不以 为前缀r)。可以使用所有八种组合:
"A string ${withInterpolation}"'A string ${withInterpolation}'"""A string ${withInterpolation} (can contain newlines)"""'''A string ${withInterpolation} (can contain newlines)'''r"A raw string, $ means nothing"r'A raw string, $ means nothing'r"""A raw string, $ means nothing (can contain newlines)"""r'''A raw string, $ means nothing (can contain newlines)'''您不能在不转义的情况下在字符串中包含字符串定界符。转义用于\确保将下一个引号字符用作字符串内容,而不是分隔符,但转义在原始字符串中不起作用 - 在原始字符串中,a\只是一个\字符,就像 a$只是一个字符而不是插值起始符.
因此,要"在字符串中包含 a ,您可以使用转义符,或使用除". 这仅排除了用作分隔符且不能使用转义符的r" ... "字符串"。
"a \"quoted\" text."'a "quoted" text.'"""a "quoted" text.""".r" ... ".这为您编写字符串提供了很大的灵活性。使用原始的“多行”字符串作为三重引号,即使它实际上并不跨越多行,也允许您在字符串中同时包含引号字符和美元/反斜杠,例如:
var complexString = r"""I don't know if "amazing" is what I'd call this $-price""";
Run Code Online (Sandbox Code Playgroud)
只有当您需要一个包含"""和'''序列的原始字符串时,您才会陷入困境。在这种情况下,Dart 组合了两个相邻的字符串文字,即使使用不同的引号:
var veryComplexString =
r"""Dart strings start with ", r", ', r', """
r'""", r""", '
r"''', and r'''";
Run Code Online (Sandbox Code Playgroud)
最后,您还可以使用插值来包含其他类型的字符串:
var someStrings = "This string contains a ${'"'} quote character";
Run Code Online (Sandbox Code Playgroud)
使用
child: Text ("One fine day I woke up from\" Bad Mood \"was Monday"),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5592 次 |
| 最近记录: |