#coding:utf-8
def get_part(html,args={})
puts html
puts args
puts args[:s]
puts "========"
puts args["s"]
puts args.key?(:s)
puts args.key?("s")
end
html="abcd_abcd"
s="a"
e="d"
get_part(html,:s=>1,:e=>2)
a="中国a"
puts a.size
puts a.length
a="abc"
puts a.size
puts html.scan("ab")
puts $&
中间版本
#coding:utf-8
def get_part(html,args={:s=>nil,:e=>nil})
r=""
if html.nil?
return ""
else
html=html.to_s
end
_html=html
if args.length==0
return _html
else
s=0
e=-1
unless args[:s].nil?
s_idx=_html.index(args[:s])
if s_idx.nil?
return ""
end
if args[:s].class==String
s=s_idx+args[:s].length
else#使用正则的
s=s_idx+_html.slice(args[:s]).length
end
puts "~~~~~~~~~~~~~~~~~~~~~~~~~"
puts s
end
unless args[:e].nil?
e_idx=_html.index(args[:e],s+1)
puts e_idx
if e_idx.nil?
return ""
else
e=e_idx-1
end
end
puts "s==>"
puts s
puts "e==>"
puts e
_html[s..e]
end
end
html="abcd_abcd"
s="a"
e="d"
puts get_part(html,:s=>/c/,:e=>"d")
#a="中国a"
#puts a.size
#puts a.length
#a="abc"
#puts a.size
#puts html.scan("ab")
#puts $&