Ruby中常用的字符串处理函数使用实例

markyang58392 14 0 PDF 2021-01-04 04:01:37

1.返回字符串的长度 代码如下: str.length => integer 2.判断字符串中是否包含另一个串 代码如下: str.include? other_str => true or false “hello”.include? “lo” #=> true “hello”.include? “ol” #=> false “hello”.include? ?h #=> true 3.字符串插入 代码如下: str.insert(index, other_str) => str “abcd”.insert(0, ‘X’) #=> “Xabcd” “abcd”.i

用户评论
请输入评论内容
评分:
暂无评论