[分享]ruby中常用的简单字符串处理函数

阅读更多
split()
trim()
indexOf()
replaceAll()

##ruby:
String.split
"hello world".split( " ")
returns [ "hello", "world" ].


String.strip
" hello world ".strip
returns "hello world".

String.index
"hello world".index( "w")
returns 6.

String.gsub(/\s/, ',')
"hello word".gsub(\/s\, ',')
returns "hello,word"

p.s.
sub() replace first
gsub() replace all

你可能感兴趣的:(Ruby)