next up previous
Next: 8.6 構造体 Up: 8 CommonLispのデータとその比較手続き Previous: 8.4 文字


8.5 文字列

文字列はその名のとおり文字の列ですが,ベクタデータです.
<cl> (vectorp '#(a b c))
T 
<cl> (vectorp "abc")
T 
<cl> (stringp '#(a b c))
NIL 
<cl> (stringp "abc")
T
文字列の等号を調べるにはeqではだめで, equalやstring=を使う必要があります.大文字小文字を区別しない ためには,equalp, string-equalを使う必要があります.
<cl> (eq "abc" "abc")
NIL 
<cl> (eql "abc" "abc")
NIL 
<cl> (equal "abc" "abc")
T 
<cl> (string= "abc" "abc")
T 
<cl> (string= "abc" "ABC")
NIL 
<cl> (equal "abc" "ABC")
NIL 
<cl> (equalp "abc" "ABC")
T 
<cl> (string-equal "abc" "ABC")
T
文字列にも大小比較が可能です.
<cl> (stringp "abc")
T 
<cl> (string-lessp "abc" "abd")
2 
<cl> (string-lessp "abc" "ad")
1 
<cl> (string-lessp "abc" "b")
0 
<cl> (string-lessp "abc" " ")
NIL
このようにどの文字から成り立ったかを 示すために数が返ります.

generated through LaTeX2HTML. M.Inaba 平成18年5月7日