Advertisement
cd62131

Sort Word In String

Dec 14th, 2013
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.27 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. # coding: utf-8
  3. def sort_word_in_string(s)
  4.   a = s.split(/[ ,.]+/)
  5.   a.sort_by {|e| e.downcase }
  6. end
  7. # test
  8. DATA.each_line do |line|
  9.   puts line
  10.   puts sort_word_in_string(line.chomp)
  11. end
  12. __END__
  13. a s d f g h j k l
  14. q,w,e,r,t,y,u,i,o,p
  15. z.x.c.v.b.n.m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement