WORDS = %w[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options
permutations random select sentence sentences sep
separate share shuf shuffle standard system the
treat usr with words
]
WORDS = %w[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options
permutations random select sentence sentences sep
separate share shuf shuffle standard system the
treat usr with words
]
start = 0
str='sentenceselect'
str='Toshufflethenumbersbetween100and200'
length = str.length
w=[]
(start..length).each do |s|
(s+1..length).each do |x|
tmp_word=str[s...x]
w.push(tmp_word) if WORDS.count(tmp_word) > 0
end
end
#!/usr/bin/env ruby
WORDS = %q[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options
permutations random select sentence sentences sep
separate share shuf shuffle standard system the
treat usr with words
]
Subwords=WORDS.split
spec=[]
string1="sentenceselect"
string2="Toshufflethenumbersbetween100and200"
Subwords.each do |words| if string1=~/#{words}/ or string2=~/#{words}/
spec<< words if !spec.include?("#{words}")
end
end
puts spec
执行结果:
100
200
To
a
an
and
between
elect
numbers
select
sentence
sentences
shuf
shuffle
the
稍微改动了点,初学者,不知道这个符不符合要求?作者: klainogn 时间: 2014-08-09 00:21
#!/usr/bin/env ruby
WORDS = %w[
100 200 ARG Linux Note To UNIX a an and apple as
available between command commend contains delimited
dict dictionary each elect file generate input is
like line list newline numbers of on operating options