文字列操作
文字列操作は、より一般的な使用例である テキスト整形 とは別物です。文字列操作は、テキストの内容を変えるために文字列値を何らかの方法で変更します。より高度な使用例では、文字列操作関数を使ってテキスト整形操作を強化できます。
split(text, delimeter)
Section titled “split(text, delimeter)”text を delimeter のすべての箇所で分割し、文字列の配列を返します。たとえば split("hello world", " ") は 2 つのテキストオブジェクトの配列 ["hello", "world"] を返します。要素にアクセスするには [] かっこを使った配列インデックスを使います。たとえば split("hello world", " ")[0] は "hello" を返します。
replace(text, old, new)
Section titled “replace(text, old, new)”text 内の old のすべての箇所を new に置き換えます。old と new は同じ長さである必要はありません。たとえば replace("myfile.png", ".png", "") は "myfile" を返します。
strip(text)
Section titled “strip(text)”文字列の先頭または末尾にある空白やタブをすべて削除します。strip(" abc ") は "abc" を返します。
title(text)
Section titled “title(text)”単語の先頭、または任意のスペース文字の直後の文字を大文字版に置き換えます。たとえば title("lorem ipsum") は "Lorem Ipsum" を返します。
upper(text)
Section titled “upper(text)”すべての文字を大文字版に置き換えます。たとえば upper("lorem ipsum") は "LOREM IPSUM" を返します。
lower(text)
Section titled “lower(text)”すべての文字を小文字版に置き換えます。たとえば lower("LOREM IPSUM") は "lorem ipsum" を返します。