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

偶然的你
TA貢獻1841條經驗 獲得超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

LEATH
TA貢獻1936條經驗 獲得超7個贊
String類中有一個方法 public boolean contains(Sting s)就是用來判斷當前字符串是否含有參數指定的字符串 例 s1=“takecatb” s2=“te” 語句:s1.contains(s2) //s1調用這個方法 若其值為ture說明s1包含s2 若為fasle 則不包含
- 3 回答
- 0 關注
- 652 瀏覽
添加回答
舉報
0/150
提交
取消