11 posts
Posted 07 July 2015 - 02:53 PM
Hello, i have a code, but i want to get a specific line of a http.request…. But how plz ?
Does exist something like GetLine() for get a specific line ?
Thanks for futur help.
3057 posts
Location
United States of America
Posted 07 July 2015 - 02:55 PM
Well, http requests return a string… which can be manipulated.
local function getLine( str, n )
local i = 1
for line in str:gmatch( "[^\r\n]+" ) do --#matches things that are not newline characters
if i == n then --#if we're on the line you wanted
return line --#return it
end
i = i + 1
end
end
1140 posts
Location
Kaunas, Lithuania
Posted 07 July 2015 - 03:02 PM
Well, http requests return a string… which can be manipulated.
Nope, they return a table similar to the one returned by a call to fs.open() in read mode. So it's not 'GetLine()' but rather 'readLine()'. Do note that 'readLine()' does
not read a specific line, rather reading the file/response line by line. You could for example put all the lines into a table and then index that table to get a specific line:
local lines = {}
for line in response.readLine do
lines[#lines + 1] = line
end
print("The second line says:")
print(lines[2])
3057 posts
Location
United States of America
Posted 07 July 2015 - 04:32 PM
Sorry, I meant the content is a string, and therefor can be manipulated via string operators.
Both solutions work, mine wants the entire string (as returned by response.readAll), whereas your solution will want the handle (if it was made into a function).
11 posts
Posted 08 July 2015 - 03:48 PM
Thank u KingOfGamesYami.