摘要:
1获取字符串某部分s = "My kingdom for a string!"s.slice(3,7) # kingdoms[3,7] # kingdoms[/.ing/] # kings[/str.*/] # strings.slice(3).ord # 107
阅读全文
posted @ 2015-11-30 23:07
c3tc3tc3t
阅读(138)
推荐(0)
编辑
摘要:
1 单独处理字符串的字符如果处理的是ASCII码的文档使用string#each_byte注意 没有 string#each方法,String#each_byte 速度比 String#scan快 ,String#scan用于配合正则表达式时使用'foobar'.each_byte { |x| pu...
阅读全文
posted @ 2015-11-30 20:08
c3tc3tc3t
阅读(154)
推荐(0)
编辑
摘要:
ascii转字符或者字符串转ascii"a".ord # => 97"!".ord # => 33"\n".ord # => 10'a'[0] # => "a"'bad sound'[1] # => "a"'a'[0].ord # => 97'bad sound'[1].ord # => 9...
阅读全文
posted @ 2015-11-30 20:00
c3tc3tc3t
阅读(385)
推荐(0)
编辑
摘要:
在一个ruby字符串中包含表但是或者变量。想使用不同的值替换表达式或者变量1 类似java 或者python的printf-style方式template = 'Oceania has always been at war with %s.'template % 'Eurasia' # => "Oc...
阅读全文
posted @ 2015-11-30 14:00
c3tc3tc3t
阅读(165)
推荐(0)
编辑