Mik*_*wis 30
str.index(pattern)
Run Code Online (Sandbox Code Playgroud)
使用index()方法.如果找到则返回索引,否则返回nil.
用法:
ruby-1.9.2-p136 :036 > str = "Ruby is awesome"
=> "Ruby is awesome"
ruby-1.9.2-p136 :037 > str.index("is awesome")
=> 5
ruby-1.9.2-p136 :038 > str.index("testtest")
=> nil
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6817 次 |
最近记录: |