Wednesday, July 9, 2008

divide single word into sentence.

The below mention function will divide the long character word into specific sentence.
for e.g you have a input like "aaaaaaaaaaaaaaaaaaaa" you want this should be divide that means each sentence should contain 5 character "aaaaa aaaaa aaaaa aaaaa".

def word_division(char_length, comment_value)
return nil if comment_value.nil?
chunk_size = char_length
i = 0
chunks = []
while i < comment_value.to_s.length
chunks << comment_value.to_s[i,chunk_size]
i = i + chunk_size
return chunks.join(" ")

No comments: