當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


CoffeeScript String concat()用法及代碼示例


描述

此方法添加兩個或更多字符串並返回結果字符串。

用法

下麵給出的是concat()JavaScript 的方法。我們可以使用 CoffeeScript 代碼中的相同方法。

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

示例

下麵的例子演示了使用concat()CoffeeScript 代碼中的 JavaScript 方法。將此代碼保存在名稱為的文件中string_concat.coffee

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

打開command prompt並編譯 .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);

現在,打開command prompt再次運行 CoffeeScript 文件,如下所示。

c:\> coffee string_concat.coffee

在執行時,CoffeeScript 文件產生以下輸出。

Concatenated String:Hello how are you. Welcome to Tutorials Point.

相關用法


注:本文由純淨天空篩選整理自 CoffeeScript String - concat()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。