【问题标题】:Need help concatenating .JS需要帮助连接 .JS
【发布时间】:2016-02-02 08:28:28
【问题描述】:

我有以下声明。

var myStr = "This is the first sentence. ";
myStr += "This is the second sentence. ";

我的最终目标是让语句看起来像这样:

这是第一句话。这是第二句。

但是当我在 console.log 中运行代码时,我得到了这个。

"This is the first sentence. This is the second sentence."

如何在不影响用作字符串的 qoutes 的情况下删除 qoutes

【问题讨论】:

  • 通过连接以下两个字符串在多行上构建 myStr:“这是第一句。”和“这是第二句。”使用 += 运算符。
  • myStr 的值应该是 This is the first sentence。这是第二句话。使用 += 运算符构建 myStr(这些是赋值指令)。

标签: javascript string concatenation


【解决方案1】:

console.log 添加引号以将记录的值表征为字符串。

您的连接没有问题,一切都按预期工作。如果您需要控制确切的输出,请使用process.stdout.write insted。

【讨论】:

    【解决方案2】:
    var myStr = "This is the first sentence. " + "This is the second sentence.";
    

    只需要在(.) 之后有空格就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-13
      • 2018-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 2017-08-08
      相关资源
      最近更新 更多