ruby 中怎樣判斷一個字符串是不是另外一個字符串的子集?
4 回答

一只名叫tom的貓
TA貢獻1906條經驗 獲得超3個贊
c中是strstr.
ruby 1.9.3中包含:
include? other_str → true or false click to toggle source
Returns true if str contains the given string or character.
"hello".include? "lo" #=> true
"hello".include? "ol" #=> false
"hello".include? ?h #=> true

慕仙森
TA貢獻1827條經驗 獲得超8個贊
您可以通過指定 2 個索引得到 list 的子集, 叫做一個 “slice” 。返回值是一個新的 list, 它包含了 list 中按順序從第一個 slice 索引 (這里為 li[1]) 開始, 直到但是不包括第二個 slice 索引 (這里為li[3]) 的所有元素。
- 4 回答
- 0 關注
- 2628 瀏覽
添加回答
舉報
0/150
提交
取消