From: Stuart Clarke Date: 2009-07-22T00:52:15+09:00 Subject: String spliting and inclusion Hi all, I am having trouble working out some logic for my problem. I basically have a long string (320 characters) and I want to split into smaller strings no longer than 50 characters in length. At present I have the following regex: data = "big long string" puts data.scan(/{50}/) This nicely breaks up the string however there are a few problems with it, including: It only outputs 50 character chunks, therefore when it gets to the end and only 20 characters remain it misses them off the output (it outputs 6 50 characters strings and ignores the remaining 20) This regex also splits up words, which is something I don't want. I want a script to count to 50 and when it gets there, go backwards to find some white space and split it at that point, therefore not breaking up a word. As a result a number of sub strings of various sizes will be created all less than 50 chars. I hope this makes sense, to summarise I want to break up a string into a max of 50 characters without breaking up words. Thanks in advance Stuart -- Posted via http://www.ruby-forum.com/.