Coffeescript-string-split
提供:Dev Guides
CoffeeScript String-split()
説明
このメソッドは、文字列を小さな部分に分割するために使用されます。 特殊文字と整数を受け入れます。 文字は区切り文字として機能し、文字列を分割する場所を示し、整数は文字列を分割する部分の数に示します。 セパレータを渡さない場合、文字列全体が返されます。
構文
以下に、JavaScriptの* split()*メソッドの構文を示します。 CoffeeScriptコードで同じメソッドを使用できます。
string.split([separator][, limit])
例
次の例は、CoffeeScriptコードでJavaScriptの* split()メソッドを使用する方法を示しています。 このコードを *string_split.coffee という名前のファイルに保存します
my_string = "Apples are round, and apples are juicy."
result = my_string.split " ", 3
console.log "The two resultant strings of the split operation are :: "
console.log my_string
- コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c coffee string_split.coffee
コンパイル時に、次のJavaScriptが提供されます。
//Generated by CoffeeScript 1.10.0
(function() {
var my_string, result;
my_string = "Apples are round, and apples are juicy.";
result = my_string.split(" ", 3);
console.log("The two resultant strings of the split operation are :: ");
console.log(my_string);
}).call(this);
次に、*コマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。
c:\> coffee string_split.coffee
CoffeeScriptファイルを実行すると、次の出力が生成されます。
The two resultant strings of the split operation are ::
Apples are round, and apples are juicy.