Common Lisp String 常用函数用法

Strings


(char string i)

Function

Returns the ith character of string. Zero-indexed. Ignores fill pointers. Settable.

> (char "Floob-Boober" 0)
=> #\F
> (char "Floob-Boober" 1)
=> #\l
(char s j) == (aref (the string s) j)

(make-string n &key initial-element {element-type 'character))

Function

Returns a new string of n initial-elements (the default values of which is implementation-dependent).

> (make-string 4)
=> "^@^@^@^@" ; "^@" == \0

> (make-string 4 :initial-element #\L)
=> "LLLL"

(schar simple-string i)

Function

Like char but the string must be a simple string. Settable.

same as (char string i).

TODO: [simple string]: ascii characters sequence is called simple string


(simple-string-p object)

Function

Returns true if object is a simple string.

(simple-string-p x) == (typep x 'simple-string)

> (simple-string-p "hello world")
=> T
> (simple-string-p "你好,世界")
=> T

(string arg)

Function

If arg is a string, returns it; if a symbol, returns its name; if a character, returns a string containing it.

> (string "string")
=> "string"
> (let ((var "string")) 
    (string var))
=> "string"
> (string #\i)
=> "i"

(string-capitalize string &key start end)

Function

(nstring-capitalize <string> &key start end)

Function

Returns a string in which the first letter of each word is uppercase, and other characters are lowercase. Each sequence of alphabetic characters is a word. The first argument to string-capitalize may also be a symbol, in which case its name is used.

nstring-capitalize is side-effect with modified string.

> (string-capitalize "hEllo")
=> "Hello"
> (string-capitalize "hello WORLD")
=> "Hello World"
> (string-capitalize "DON'T")
=> "Don'T"  ; not "Don't"
> (string-capitalize "pipe 13a foo16c")
=> "Pipe 13a Foo16c"
> (string-capitalize "hello world" :start 5)
=> "hello World"
> (let ((var "hello")) 
    (string-capitalize var)
    (print var)
    (nstring-capitalize var)
    (print var))
=> "hello"
   "Hello"

(string-downcase string &key start end)

Function

(nstring-downcase <string> &key start end)

Function

Like string-upcase and nstring-upcase, but characters are converted to lowercase.

> (string-downcase "HELLO")
=> "hello";

(string-equal string1 string2 &key start1 end1 start1 end2)

Function

Like string= but ignores case.

(string-equal "hello" "HELLO")
=> T

(string-greaterp string1 string1 &key start1 end1 start2 end1)

Function

Like string > but ignores case.

 > (string-greaterp "hellp" "HELLO")
 => 4

 > (string> "hellp" "HELLO")
 => 0

(string-upcase string &key start end)

Function

(nstring-upcase <string> &key start end)

Function

Returns a string in which lowercase characters are replaced by the corresponding uppercase ones. The start and end are used as in sequence functions. The first argument to string-upcase may also be a symbol, in which case its name is used.

> (string-upcase 'hello)
=> "HELLO"

(string-left-trim seq string)

Function

Like string-trim, but only trims from the front.

> (string-trim-left " ( *three (silly) word* )")
=> "three (silly) word* )"

(string-lessp string1 string2 &key start1 end1 start2 end2)

Function

Like string< but ignores case.

> (string-lessp "HELLO" "hello")
=> NIL
> (string< "HELLO" "hello")
=> 0

(string-not-equal string1 string2 &key start1 end1 start2 end2)

Function

Like string/= but ignores case.

> (string-not-equal "HELLO" "hello")
=> NIL

(string-not-greaterp string1 string2 &key start 1 end1 start2 end2)

Function

Like string<= but ignores case.

> (string-not-greaterp "HELLO" "hello")
=> 5
> (string<= "HELLO" "hello")
=> 0

(string-not-lessp string1 string2 &key start1 end1 start2 end2)

Function

Like string>= but ignores case.

> (string-not-lessp "hello" "HELLO")
=> 5
> (string>= "hello" "HELLO")
=> 0

(stringp object)

Function

Returns true if object is a string.

> (stringp "string")
=> T
> (stringp 'string)
=> NIL
> (stringp 13)
=> NIL

(string-right-trim seq string)

Function

Like string-trim, but only trims from the back.

(string-right-trim " (*)" " ( *three (silly) words* ) ")
=> " ( *three (silly) words"    

(string-trim seq string)

Function

Returns a string like string, but with any characters that appear in seq removed from either end.

(string-trim '(#\Space #\Tab #\Newline) " garbanzo beans")
=> "garbanzo beans" 
(string-trim " (*)" " ( *three (silly) words* ) ")
=> "three (silly) words" 

(string= string1 string2 &key start1 end1 start2 endl)

Function

Returns true if the subsequences of string1 and string2 are the same length and contain the same characters. The parameters start1 and end1, and start2 and end2, work like the usual start and end parameters for string1 and string2 respectively.

> (string= "hello" "hello")
=> T
> (string= "hello" "HELLO")
=> NIL

(string/= string1 string2 &key start1 end1 start2 endl)

Function

Returns true if string= would return false.

> (string/= "hello" "HELLO")
=> 0
> (string/= "hello" "hello")
=> NIL

(string< string1 string2 &key start1 end1 start2 end2)

Function

Returns true if the two subsequences contain the same characters up to the end of the first, and the second is longer; or if the subsequences contain diferent characters, and where they difer for the first time, the character in the first substring is char< the one in the second. The parameters are the same as in string=.

> (string< "hello" "jello")
=> 0
> (string< "hello" "aello")
=> NIL
> (string< "hello" "hello")
=> NIL

(string> string1 string2 &key start1 end1 start2 end2)

Function

Returns true if the two subsequences contain the same characters up to the end of the second, and the first is longer; or if the subsequences contain diferent characters, and where they difer for the first time, the character in the first substring is char> the one in the second. The parameters are the same as in string=.

> (string> "hello" "jello")
=> NIL
> (string> "hello" "aello")
=> 0
> (string> "hello" "hello")
=> NIL

(string<= string1 string2 &key start1 end1 start2 endl)

Function

True if the arguments are string< or string=.

> (string<= "hello" "jello")
=> 0
> (string<= "hello" "aello")
=> NIL
> (string<= "hello" "hello")
=> 5

(string>= string1 string2 &key start1 end1 start2 end2)

Function

True if the arguments are string> or string=.

> (string>= "hello" "jello")
=> NIL
> (string>= "hello" "aello")
=> 0
> (string>= "hello" "hello")
=> 5

转载于:https://my.oschina.net/u/563463/blog/157065

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值