"hello".index('e') #=> 1 "hello".index('lo') #=> 3 "hello".index('a') #=> nil "hello".index(?e) #=> 1 "hello".index(/[aeiou]/, -3) #=> 4
" now's the time".split #=> ["now's", "the", "time"] " now's the time".split(' ') #=> ["now's", "the", "time"] " now's the time".split(/ /) #=> ["", "now's", "", "the", "time"] "1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"] "hello".split(//) #=> ["h", "e", "l", "l", "o"] "hello".split(//, 3) #=> ["h", "e", "llo"] "hi mom".split(%r{\s*}) #=> ["h", "i", "m", "o", "m"] "mellow yellow".split("ello") #=> ["m", "w y", "w"] "1,2,,3,4,,".split(',') #=> ["1", "2", "", "3", "4"] "1,2,,3,4,,".split(',', 4) #=> ["1", "2", "", "3,4,,"] "1,2,,3,4,,".split(',', -4) #=> ["1", "2", "", "3", "4", "", ""]
a = 'cruel world' a.scan(/\w+/) # ["cruel", "world"]
puts "hello".sub(/[aeiou]/, '*') puts "hello".sub(/([aeiou])/, '<\1>') puts "service.a.com".sub("com", "co.kr")
"abcd".succ #=> "abce" "THX1138".succ #=> "THX1139" "<<koala>>".succ #=> "<<koalb>>" "1999zzz".succ #=> "2000aaa" "ZZZ9999".succ #=> "AAAA0000" "***".succ #=> "**+"
"hello".chomp #=> "hello" "hello\n".chomp #=> "hello" "hello\r\n".chomp #=> "hello" "hello\n\r".chomp #=> "hello\n" "hello\r".chomp #=> "hello" "hello \n there".chomp #=> "hello \n there" "hello".chomp("llo") #=> "he"
Content-Type: multipart/alternative; boundary=047d7bd9037c9c372204e0f68a9d --047d7bd9037c9c372204e0f68a9d
str =<<eof Content-Type: multipart/alternative; boundary=047d7bd9037c9c372204e0f68a9d --047d7bd9037c9c372204e0f68a9d eof boundstr = 'boundary=' start_p = str.index(boundstr) end_p = str[start_p..-1].index("\n") puts str[(start_p+boundstr.length)..(start_p+end_p)]
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
Contents
String
index (substring [,offset]) -> fixnum or nil
index (regexp [,offset]) -> fixnum or nil
split (pattern=$;, [limit]) -> anArray
scan
sub (pattern, replacement) -> new_str
sub (pattern, hash) -> new_str
sub (pattern){|match| block} -> new_str
succ -> new_str
next -> new_str
chomp(separator=$/) -> new_str
사용 예
특정 패턴사이에 있는 문자열 가져오기
히스토리
Recent Posts
Archive Posts
Tags