Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def title_case(str,exceptions)
- str = str.split(" ")
- nstr = []
- do_cap = true
- for i in 0..str.length-1
- do_cap = true
- for e in exceptions
- if str[i] == e
- do_cap = false
- nstr << str[i].to_s
- end
- end
- if do_cap == true
- str[i] = cap(str[i])
- nstr << str[i]
- end
- end
- nstr = nstr.join(" ")
- return nstr
- end
- def cap(str)
- str = str.split("")
- length = str.length
- p1 = str[0].upcase
- p2 = str.slice!(1..length)
- return p1.to_s+p2.to_s
- end
- puts title_case("This is a string",["is","a"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement