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?

部分文字列とリストの比較

これまで、リストのような機能を提供する $Piece と区切り文字について学習しました。区切り文字のことを考えたくない場合に、リストは便利です。区切り文字を使用した場合、いずれかの部分文字列に区切り文字が含まれている可能性が常にあり、その場合、文字列内の残りの要素の位置が変わってしまいます。リストはこれを防ぎます。

以下で、リストの表示方法を 2 つ示します。部分文字型関数は、類似のリスト型関数を持っています。その違いは区切り文字の有無によります。ここでは、$ListFind$Find よりも便利です。$ListBuild で構築される変数 LmailWrite コマンドで表示できますが、制御文字を含むため、お勧めできません。したがって、専用の List 関数を使用してリストにアクセスするようにします。ターミナルを使用したリストの操作時には、Zwrite コマンドを使用してリストの内容を (単純変数、配列、またはグローバルで) 表示できます。

SAMPLES>set addr = "One Memorial Drive"

SAMPLES>set city = "Cambridge" ; for both examples below

SAMPLES>set st = "MA", zip = "02142" ; for both examples below

SAMPLES>set Pmail = addr _ "^" _ city _ "^" _ st _ "^" _ zip

SAMPLES>set Lmail = $listbuild(addr, city, st, zip)

SAMPLES>write $piece(Pmail, "^", 2), ?20, $list(Lmail, 2)
Cambridge           Cambridge
SAMPLES>write $length(Pmail, "^"), ?20, $listlength(Lmail)
4                   4
SAMPLES>write $find(Pmail, "MA"), ?20, $listfind(Lmail, "MA")
32                  3
SAMPLES>write Pmail
One Memorial Drive^Cambridge^MA^02142
SAMPLES>zwrite Lmail
Lmail=$lb("One Memorial Drive","Cambridge","MA","02142")

FeedbackOpens in a new tab