CoffeeScript 字串 - toLocaleUpperCase()



描述

該方法用於將字串中的字元轉換為大寫,同時遵守當前區域設定。對大多數語言而言,它返回的輸出與 toUpperCase 相同。

語法

下面給出了 JavaScript 的 toLocaleUpperCase() 方法的語法。我們可以在 CoffeeScript 程式碼中使用相同的方法。

string.toLocaleUpperCase()

示例

以下示例演示了在 CoffeeScript 程式碼中使用 JavaScript 的 toLocaleUpperCase() 方法。將此程式碼儲存在名為 toLocaleUpperCase.coffee 的檔案中

str = "Apples are round, and Apples are Juicy.";
console.log str.toLocaleUpperCase()

開啟 命令提示符 並按如下所示編譯 .coffee 檔案。

c:\> coffee -c coffee toLocaleUpperCase.coffee

編譯時,它會提供以下 JavaScript。

// Generated by CoffeeScript 1.10.0
(function() {
  var str;

  str = "Apples are round, and Apples are Juicy.";

  console.log(str.toLocaleUpperCase());

}).call(this);

現在,再次開啟 命令提示符 並按如下所示執行 CoffeeScript 檔案。

c:\> coffee toLocaleUpperCase.coffee

執行時,CoffeeScript 檔案會生成以下輸出。

APPLES ARE ROUND, AND APPLES ARE JUICY.
coffeescript_strings.htm
廣告
© . All rights reserved.