local tLines = {}
local lineLength = (51)
local message = "This is the first line|second line|This line is longer than the 51 character limit, and will be split!"
while #message > 0 do
local line = message:sub(1,lineLength)
local newLine = line:find"|" --check for new line character
if newLine then
line = line:sub(1,newLine-1)
message = message:sub(#line+2,#message)
elseif #line == lineLength then
local endSpace = line:find"%s%S-$" or lineLength
line = line:sub(1,endSpace)
message = message:sub(#line+1,#message)
else
message = ""
end
table.insert(tLines,line)
end
for i=1,#tLines do
print(tLines[i])
end
As expected splits the string into lines at all "|" and at the space closest to the length limit, and prints the following:
Quote
This is the first line
second line
This line is longer than the 51 character limit,
and will be split!
second line
This line is longer than the 51 character limit,
and will be split!
However, running it on a computercraft computer prints the following
Quote
This is the first line
second line| This line is longer th
n the 51 character limit, and will be split!
second line| This line is longer th
n the 51 character limit, and will be split!
Edited by CometWolf, 11 January 2014 - 07:54 AM.











