Friday 15 February 2013

Lua string operation -


I'm trying to find a way to add a new line ("\ n"), yet unsuccessful A very long string.

Is there a function that will insert a new row of every x letters? Basically, I need to add a new line to every 95 characters. Here is the text I am working with:

Memorandum for the record

Subject: topic

1) Consululate YU Im Ali Lubertis Waltatatum ID, Daniel Elegentitetinx Anyway, Duo investigation was disgusted with the only former Elite pledges Kasd erant dolorum id sed, it is very important, because it is different from my family.

2) To know more about all of Fabelas Lucalias Vim, the Institute of Information Technology, the advertisement was sincerely connected to the Mali animals. 3) The person who applied for the use of the Noula, Odio wisi torquatos thanks to the sea Q, for Vim only for epicurers at any time for you, the game for you already You can. 4) The question to be asked about one of these two was answered.

4) It was attacked and charged, and any of its enemies were blamed on it. Works for one liquor, which works for soft baths, and the color of makeup and minerals. And it is very simple and quick to clear. For the only time, we all choose to choose the best option and the place for more and more, which affects the most, affects all, affects all.

I am interpreting this question as: I read the text in most of the lines I want to split in, but as close as possible, break the 95 characters in white space.

I am ignoring file io in other replies. Here goes:

  - Controls to break the second parameter; 80 missed Call me: Breakout (LongestString, 95) Local Function Break At (String, Line Lang) Local Line Langline = Line length or 80-array is more efficient for large text operations. Local out = {} - Milan line without Newline; For the original Neulines save line, break in the straw: gmatch ('([^ \ n] +) (\ n +)') Local count = 0 - '' 'with white space of the brain without any adjacent white spot To allow the last word of the line. For the word, in the spaces line: gmatch ('(% S +) (% s *)') count = count + #word if calculation & gt; So if the word crosses the line line line, then change the last word 'empty space with a new line out [#out] =' \ n '- The current word is the first on the new line. Count = #word end count = count + #whitespace table.insert (outside, word) table.insert (outside, white space) ending table.insert (out, break) end return table.concat (out) termination   

This will break the strips in white space, maximize the number of words on one line.

No comments:

Post a Comment