String (クラス)
public final serializable String {inherits ReadOnlyString}
パッケージ: CURL.LANGUAGE.STRINGS

文字 (char) の読み取り専用文字列。

注意事項

以下に、Curl の文字列クラスの階層を示します。
Curl の文字列に関する詳細は、Curl 開発者ガイド: 文字列 を参照してください。

プログラミング注意事項

コンストラクタ
{String ...}
は、各引数の String 式を連結した String を作成します。すべての残余引数に対する String 式が連結され、新しい String オブジェクトに対する値を形成します。各 rest-arg に対する String 式を取得するには、{format "%s", rest-arg} を呼び出すか、またはより高速な同等の処理を実行します。

文字列リテラルが使われた場合、Curl コンパイラは自動的に String を作成します。したがって、たとえば次のようなコードを記述する必要はありません
let s:String = {String "hello world"}
この場合、次のように記述するだけで済みます。
let s:String = "hello world"

次の例は、さまざまなデータ型の異なる引数を複数個指定して文字列を作成するものです。
{String "This String is created with ", 3, " arguments"}

コンストラクタ
default:新しい String を作成します。引数を文字列に変換し、その文字列を連結します。連結した結果を String の値に変換します。
ファクトリ public {String.default ...:any}:String
repeat-char:n 個の c の文字列を返します。
ファクトリ public {String.repeat-char c:char, n:int}:String

プロパティ
for-loop-count:文字列に対して繰り返し処理を実行するコンテナである for ループが出現したときに Curl コンパイラが使うゲッター。
アクセサ public final inline String.for-loop-count:int
size:self 内の文字数。
アクセサ public final inline String.size:int
プロパティ 継承 StringInterface: empty?

メソッド
clone:
public {String.clone}:ReadOnlyString
equal?:self と、指定された StringInterface が等しいかどうかを検査します。
public {String.equal?
str:StringInterface,
ignore-case?:bool = false
}:bool
get:self 内の指定された文字を返します。
public final {String.get index:int}:char
substr:self の指定された部分文字列を返します。
public {String.substr start:int, length:int}:String
to-String:self と同一 (==) の String を作成します。
public final inline {String.to-String}:String
メソッド 継承 StringInterface: compare, find, find-char-class, find-string, prefix?, replace-clone, split, suffix?, tail, to-double, to-InputStream, to-int, to-int64, to-lower-clone, to-upper-clone, trim-clone, trim-left-clone, trim-right-clone
メソッド 継承 Object: object-describe, object-describe-for-debugging, object-serialize



コンストラクタ詳細
default (ファクトリ)
public {String.default ...:any}:String

新しい String を作成します。引数を文字列に変換し、その文字列を連結します。連結した結果を String の値に変換します。



repeat-char (ファクトリ)
public {String.repeat-char c:char, n:int}:String

n 個の c の文字列を返します。




プロパティ詳細
for-loop-count (アクセサ)
アクセサ public final inline String.for-loop-count:int

文字列に対して繰り返し処理を実行するコンテナである for ループが出現したときに Curl コンパイラが使うゲッター。

注意事項

このゲッターを直接呼び出さないでください。このゲッターは、Curl コンパイラによってのみ使われるよう用意されているものです。


size (アクセサ)
アクセサ public final inline String.size:int

self 内の文字数。

戻り値

文字数を示す int 値。

説明

読み取り専用文字列の場合 書き込み可能文字列の場合 size をその文字列の現在のサイズよりも小さい値に設定した場合、その文字列は切り詰められます。size を現在のサイズよりも大きい値に設定した場合、差分の文字数がその文字列の末尾に追加されます。この場合、追加される文字の値は Unicode 値の 0000 になります。

次の例は、読み取り専用文字列に対して size を使用した場合です。


{value
    || Declare and initialize a read-only string
    let s:String = "Hello World!"

    || Output a message that includes the return value of
    || a call to "size".
    || Note that you must use "value" to display the value
    || of "s.size", rather than the text "s.size".
    {text There are {value s.size} characters in the string.}
}


次の例は、書き込み可能文字列に対して size を使用した場合です。


{value
    || Declare and initialize a writable string.
    let sb:StringBuf = {StringBuf "Hello World!"}

    || Set the size of the string to 5 characters.
    || The string should now contain only the first five
    || characters, "Hello".
    set sb.size = 5

    || Output a message that includes the new string
    {text If {monospace size} is set to 5, the string
        becomes: {value sb}}
}



{value
    || Declare and initialize a writable string.
    let sb:StringBuf = {StringBuf "Hello World!"}

    || Set the size of the string to 20 characters.
    || The string should now have 8 characters
    || with the Unicode value 0000 at the end.
    set sb.size = 20

    || Output a message that includes the new string.
    {text Then, if {monospace size} is set to 20, the string
        becomes: {value sb}}
}

注意事項

これは StringInterface の抽象ゲッターです。このゲッターは StringInterface のサブクラスによって実装されます。





メソッド詳細
clone (メソッド)
public {String.clone}:ReadOnlyString
この項目はサポートされていません。内部使用限定となっています。


equal? (メソッド)
public {String.equal?
str:StringInterface,
ignore-case?:bool = false
}:bool

self と、指定された StringInterface が等しいかどうかを検査します。

str: 等しいかどうか比較する StringInterface
ignore-case?: 検査時に大文字と小文字の区別を無視するかどうかを示すキーワード引数。既定では、大文字と小文字の区別は無視されません (ignore-case? = false)。つまり、既定では大文字と小文字は区別されます。たとえば、"abcdefg""ABCDEFG" は等しくありません。

ignore-case? はキーワード引数です。ignore-case? を指定するには、メソッド呼び出しのキーワードに対して適切な値を設定します (例:ignore-case? = true)。

ignore-case?true を設定した場合、検査時に大文字と小文字は区別されません。この場合、"abcdefg""ABCDEFG" は等しいと評価されます。

戻り値

bool 値。self 内の各文字が str 内の対応する文字と等しい場合、true を返します。それ以外の場合は、false を返します。


{value
    || Declare and initialize two strings
    let s1:String = "Hello World!"
    let s2:String = "hello world!"

    || Display the strings.
    {text
        String 1: {value s1}
        {br}String 2: {value s2}

        || Test if the two strings are equal and display
        || an appropriate message.
        {if {s1.equal? s2} then
            {text The strings are equal.}
         else
            {text The strings are NOT equal.}
        }

        || Test if the two strings are equal, this time
        || ignoring case, and display an appropriate message.
        But, if you ignore case,
        {if {s1.equal? s2, ignore-case? = true} then
            {text they are equal.}
         else
            {text they are NOT equal.}
        }
    }
}


get (メソッド)
public final {String.get index:int}:char

self 内の指定された文字を返します。

index: 取得する文字の位置。最左端の文字の位置は 0 です。最右端の文字の位置は (self.size - 1) です。有効値は 0(self.size - 1) の範囲です (0(self.size - 1) を含む)。

例外のスロー

index が範囲外の場合は ArrayBoundsException をスローします。


{value
    || Declare and initialize a string.
    let s:String = "Hello World!"

    || Display the string and return the
    || character at position 7.
    || Remember that the leftmost position
    || is 0 (zero).
    {text {value s}
        {br}The character at position 7 is {s.get 7}.}
}

注意事項

これは StringInterface の抽象メソッドです。このメソッドは StringInterface のサブクラスによって実装されます。


substr (メソッド)
public {String.substr start:int, length:int}:String

self の指定された部分文字列を返します。

start: self 内における部分文字列の開始位置。最左端の文字の位置は 0 です。最右端の文字の位置は (self.size - 1) です。有効値は 0 ~ (self.size - 1) の範囲です (0 と (self.size - 1) を含む)。
length: 部分文字列の長さ。つまり、部分文字列内の文字数です。

戻り値

self の指定された部分文字列が格納された String。この部分文字列は、start の位置から始まる length 個の連続した文字です。

注意事項

start または start + length が範囲外を指している場合、このメソッドは ArrayBoundsException をスローします。


{value
    || Declare and initialize s1 (the original string).
    let s1:String = "Hello World!"

    || Initialize s2 with a substring of s1.  The
    || substring begins at position 6 and is 5
    || characters long ("World").
    || Remember that the leftmost position
    || is 0 (zero).
    let s2:String = {s1.substr 6, 5}

    || Display the contents of s2.
    {value s2}
}

注意事項

クローン作成の詳細については、『Curl 開発者ガイド』の「文字列クローンの操作」のセクションを参照してください。


to-String (メソッド)
public final inline {String.to-String}:String

self と同一 (==) の String を作成します。

戻り値

self 内の文字を含む String


{value
    || Define and initialize a StringBuf.
    let sb:StringBuf = {StringBuf "Hello World!"}

    || Convert the StringBuf to a String.
    let s:String = {sb.to-String}

    || Display the contents of the String.
    {value s}
}