Posted 11 January 2014 - 07:39 AM
Running this piece of code on the online lua demo http://www.lua.org/cgi-bin/demo
As expected splits the string into lines at all "|" and at the space closest to the length limit, and prints the following:
However, running it on a computercraft computer prints the following
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:
This is the first line
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
And im just left thinking… wtf is going on here?This is the first line
second line| This line is longer th
n the 51 character limit, and will be split!
Edited on 11 January 2014 - 06:54 AM