- 论坛徽章:
- 5
|
- #!/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
- permutations random select sentence sentences sep
- separate share shuf shuffle standard system the
- treat usr with words
- ]
- string1="sentenceselect"
- string2="Toshufflethenumbersbetween100and200"
- class String
- def ssss(words, rs=[])
- words.each do |x|
- if self =~ /^#{x}/
- rs =[x]+ self.sub(x,"").ssss(words,rs)
- end
- end
- rs
- end
- end
- p string1.ssss(WORDS)
- p string2.ssss(WORDS)
- ["sentences", "elect", "sentence", "select"]
- ["To", "shuffle", "the", "numbers", "between", "100", "and", "200", "an", "a", "shuf"]
复制代码 写的不好,没有完全达到效果 |
|