文字列自体を変更せずに文字列の変更バージョンを作成するには、clone ファミリのメソッドを使用します。これらのメソッドは、元の文字列オブジェクトと同じ内容に、指定された変更内容を加えて新しい文字列オブジェクトを返します。これらのメソッドは、読み取り専用の文字列の内容を変更する場合に特に便利です。Curl® 言語では、次のような文字列クローンに関する操作を提供しています。
| 読み取り専用 | 読み取り / 書き込み | 要約 |
trim-clone | Y | Y | クローンを作成して、文字列の最初と最後から文字を削除するメソッド。 |
trim-left-clone | Y | Y | クローンを作成して、文字列の最初から文字を削除するメソッド。 |
trim-right-clone | Y | Y | クローンを作成して、文字列の最後から文字を削除するメソッド。 |
クローンを作成して文字をトリミングするには、
trim-clone、
trim-left-clone、および
trim-right-clone メソッドを使用します。これらのメソッドはクローンの端からトリム文字でない文字の位置まで、連続してトリム文字を削除します。
trim-clone は、クローンを作成してそのクローンの左端と右端から文字を削除します。
trim-left-clone は左端のみ、
trim-right-clone は右端のみ削除します。既定ではこれらのメソッドは空白をトリミングします。他の文字をトリミングするには、
trim-chars キーワード引数を使用してその文字を含む
CharClass オブジェクトを渡します。
CharClassオブジェクトの詳細については、「
文字クラス」のセクションを参照してください。次の例でこれらのメソッドを示します。
例:
文字のトリミング |
 |
|| Declare and initialize a read-only string.
{let s1:String = " -=-Hello World!!! "}
|| Output the value of the string.
{value s1}
|| Create a clone and trim whitespace from both ends.
{let s2:String = {s1.trim-clone}}
|| Output the value of the clone.
{value s2}
|| Create another clone and trim '-' and '=' characters from the left.
{let s3:String = {s2.trim-left-clone trim-chars="-="}}
|| Output the value of the second clone.
{value s3}
|| Create a third clone and trim '!' characters from the right.
{let s4:String = {s3.trim-right-clone trim-chars="!"}}
|| Output the value of the third clone.
{value s4}
| |
文字列クローンの作成時に新しいオブジェクトを作成できたかどうかを確認するには、上記の例を変更して他の文字列 (s1、s2、または s3) の値を返してみてください。
| 読み取り専用 | 読み取り / 書き込み | 要約 |
to-lower-clone | Y | Y | クローンを作成して、含まれている文字を小文字に変換するメソッド。 |
to-upper-clone | Y | Y | クローンを作成して、含まれている文字を大文字に変換するメソッド。 |
クローンを作成してそれに含まれる文字をすべて小文字にするには、to-lower-clone メソッドを使用します。クローンを作成してそれに含まれる文字をすべて大文字にするには、to-upper-clone メソッドを使用します。次の例でこれらのメソッドを示します。
例:
クローンの大文字と小文字の変更 |
 |
|| Declare and initialize a read-write string.
{let s1:String = "Hello World!"}
|| Create a clone and convert the characters in it to lowercase.
{let s2:String = {s1.to-lower-clone}}
|| Output the value of the clone.
{value s2}
|| Create another clone and convert the characters in it to uppercase.
{let s3:String = {s2.to-upper-clone}}
|| Output the value of the second clone.
{value s3}
| |
文字列クローンの作成時に新しいオブジェクトを作成できたかどうかを確認するには、上記の例を変更して他の文字列 (s1 または s2) の値を返してみてください。
Copyright © 1998-2019 SCSK Corporation.
All rights reserved.
Curl, the Curl logo, Surge, and the Surge logo are trademarks of SCSK Corporation.
that are registered in the United States. Surge
Lab, the Surge Lab logo, and the Surge Lab Visual Layout Editor (VLE)
logo are trademarks of SCSK Corporation.