易截截图软件、单文件、免安装、纯绿色、仅160KB

转载——Ruby字符串处理

转自:http://developer.51cto.com/art/200912/170762.htm 
Ruby字符串处理函数总结列表分享
Ruby字符串处理函数包括返回字符串长度函数;判断字符串中是否包含另一个串函数;字符串插入;字符串分隔,默认分隔符为空格等等。
 
str.length => integer 
str.include? other_str
 => true or false  
"hello".include? "lo"
 #=> true  
"hello".include? "ol"
 #=> false  
"hello".include? ?h
 #=> true 
Ruby语言对于编程人员来说是一项非常有用的函数。学好这项语言可以帮助我们实现简便轻松的编写方式。下面我们向大家介绍一下Ruby字符串处理函数的一些基本概念。
Ruby字符串处理函数1.返回字符串的长度
Ruby字符串处理函数2.判断字符串中是否包含另一个串
Ruby字符串处理函数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" 
Ruby字符串处理函数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(//) #=> 
["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,,".spl


相关文档:

Ruby Shoes 的鼠标事件

因为一次偶然的机会接触了Ruby语言。然后下载了Ruby Shoes工具。
发现Ruby还是蛮有趣的。
花了一段时间熟悉了它的语法。
下面来试试它的鼠标功能。
Shoes.app do
  #图片初始化
  @img = image "http://www.google.cn/intl/zh-CN/images/logo_cn.gif"
  #图片关于鼠标的调用
 & ......

Ruby的装饰器模式实现

class Tree
def initialize
puts "Make a normal tree"
end
def decorate
puts "Make sure the tree won\'t fall"
end
end
class RedBalls < Tree
def initialize(tree)
@parent = tree;
end
def decorate
@parent.decorate
puts "Put on some red balls"
end
end ......

ruby on rails 解决multiple select 存储和update

操作系统ubuntu,开发工具netbeans
vendor数据库表有字段service_category varchar(100)
<% form_for :vendor, @vendor, :url => sellers_path do |f| %>
  <%= f.select(:service_category,
                  ......

Ruby学习笔记一——语言基础


#一、这里是注释,是单行注释,类似于//
puts 3/5#这里是整数形式的结果
puts 3/5.0#这里是小数形式的结果
=begin
  这是多行注释,实际上这也是Ruby内嵌文档格式,类似于Java doc
  =end不但要有起止,还要缩进才有用。
=end
#二、连行
puts "Hello Ruby!"; puts "This is a "\
"String";# ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号