Send this to a friend
1 def trim_by_words(string,wordcount)
2 string.split[0..(wordcount-1)].join(" ") +(string.split.size > wordcount ? "..." : "")
3 end
4
5
6 string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
7
8 puts trim_by_words(string,10)
def trim_by_words(string,wordcount)
string.split[0..(wordcount-1)].join(" ") +(string.split.size > wordcount ? "..." : "")
end
string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
puts trim_by_words(string,10)