假设您具有以下代码:
if (isProd) {
console.log(`hello!, We're on a production \
machine`)
}
当isProd为true时,输出看起来如下:
hello!, We're on a production machine
您可以看到在“生产”和“机器”之间有一个选项卡。这是由缩进引起的。
我想问一下如何编写代码,即缩进标签将包含在字符串中,我的意思是我该怎么做才能获得以下输出:
hello!, We're on a production machine
编辑: 我看到了这里提出的解决方案:Regex to replace multiple spaces with a single space 这不是一个糟糕的解决方案,但我想知道我们是否可以避免使用正则表达式。 Javascript中的反斜杠()已经意味着忽略换行符。没什么可忽略的制表符/空格吗?
顺便说一句,Kotlin具有这样的功能:
val myString = """
|Kotlin is interesting.
|Kotlin is sponsored and developed by JetBrains. """