Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

文字列関数 (2)

$Piece には他にも特徴があります。単一の文字ではなく、指定した範囲の部分文字列を返します。異なる区切り文字を使用して、同じ文字列から部分文字列を返すこともできます。$Piece は返り値が空の場合、空文字列を返します (1 つ目と 2 つ目の区切りの前に値がない場合)。

$Piece 関数を使用して、1 つの文字列に複数の部分文字列を含ませ、任意の区切り文字 (例えば “^”) で、文字列を分割できます。長い文字列はレコードとして、部分文字列はそのフィールドとして動作します。また、$Length には部分文字型の変異形があり、区切りを元にして文字列内の部分文字列数を返します。

SAMPLES>write $piece("slice of pizza", " ", 1, 2)
slice of
SAMPLES>write $piece("slice of pizza", "i", 2)
ce of p
SAMPLES>write $piece("slice of pizza", "z", 2)

SAMPLES>set city=$piece("One Memorial Drive^Cambridge^MA^02142", "^", 2)

SAMPLES>write city
Cambridge
SAMPLES>write $length("slice of pizza", " ")
3
SAMPLES>
FeedbackOpens in a new tab