ruby的字符串处理函数
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".insert(3, 'X') #=> "abcXd" "abcd".insert(4, 'X') #=> "abcdX" "abcd".insert(-3, 'X') -3, 'X') #=> "abXcd" "abcd".insert(-1, 'X') #=> "abcdX" 4.字符串分隔,默认分隔符为空格 str.split(pattern=$;, [limit]) => anArray " now's the time".split #=> ["now's", "the", "time"] "1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"] "hello".split(//) #