CoffeeScript 字符串 - concat()



说明

此方法将两个或多个字符串相加,并返回结果字符串。

语法

以下是 JavaScript concat() 方法的语法。我们可以从 CoffeeScript 代码使用相同的方法。

string.concat(string2, string3[, ..., stringN]);

示例

以下示例演示了如何在 CoffeeScript 代码中使用 JavaScript 的 concat() 方法。将此代码保存到名为 string_concat.coffee 的文件中

str1 = "Hello how are you. "
str2 = "Welcome to Tutorials Point."
str3 = str1.concat str2
      
console.log "Concatenated String :" + str3 

打开 命令提示符 并编译 .coffee 文件,如下所示。

c:\> coffee -c string_concat.coffee

在编译时,它会给你以下 JavaScript。

// Generated by CoffeeScript 1.10.0
(function() {
  var str1, str2, str3;

  str1 = new String("Hello how are you. ");

  str2 = new String("Welcome to Tutorials Point.");

  str3 = str1.concat(str2);

  console.log("Concatenated String :" + str3);

}).call(this);

现在,再次打开 命令提示符 并运行 CoffeeScript 文件,如下所示。

c:\> coffee string_concat.coffee

在执行时,CoffeeScript 文件会产生以下输出。

Concatenated String :Hello how are you. Welcome to Tutorials Point.
coffeescript_strings.htm
广告
© . All rights reserved.