Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
uncut words string
4 Posts
uncut words string

Interesting how much this looks like a homework assignment.

bq. It cuts the string after every 10 characters into like this

And yet:

"Kid games need to be both fun and educat".length => 40

What am I missing here Amit? Your requirements aren't matching your examples, and the code sample doesn't run.

words.scan(/.{0,10}\s*(?:\b)/) should work

I have this paragraph as one srting , apllied below code as suggested by one of the member.

words = "Kid games need to be both fun and educational. Aimed at ages pre-K through middle school, safe environment to discover their abilities and learn new skills with interactive and fun computer games. Our games build skills in math, logic, memory, vocabulary, alphabet, spelling."

line_length = 10

word_arry = words.split(" ")

text = (0..(words.length / line_length)).inject([]) {|v,num| start = num * line_length; v << %Q{}}

text.join("\n")

It cuts the string after every 10 characters into like this

What i need is the words remain uncut if it comes in the range like in first line i want eductaional to be complete if it is not in range than it wil show upto "and"

any kind of help highly appreciated,its a urgent need.Please provide any way to it.

Regards & thanks

amit

4 Posts
Login to add your message