Advertisement
Guest User

Challenge #76

a guest
Aug 25th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.53 KB | None | 0 0
  1. def title_case(str,exceptions)
  2.     str = str.split(" ")
  3.     nstr = []
  4.     do_cap = true
  5.     for i in 0..str.length-1
  6.         do_cap = true
  7.         for e in exceptions
  8.             if str[i] == e
  9.                 do_cap = false
  10.                 nstr << str[i].to_s
  11.             end
  12.         end
  13.         if do_cap == true
  14.             str[i] = cap(str[i])
  15.             nstr << str[i]
  16.         end
  17.     end
  18.     nstr = nstr.join(" ")
  19.     return nstr
  20. end
  21.  
  22. def cap(str)
  23.     str = str.split("")
  24.     length = str.length
  25.     p1 = str[0].upcase
  26.     p2 = str.slice!(1..length)
  27.     return p1.to_s+p2.to_s
  28.    
  29. end
  30.  
  31. puts  title_case("This is a string",["is","a"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement