Jump to content




GetLine(), does it exist?


4 replies to this topic

#1 asto63

  • Members
  • 11 posts

Posted 07 July 2015 - 01: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.

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 July 2015 - 01: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


#3 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 07 July 2015 - 02:02 PM

View PostKingofGamesYami, on 07 July 2015 - 01:55 PM, said:

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])


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 July 2015 - 03: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).

#5 asto63

  • Members
  • 11 posts

Posted 08 July 2015 - 02:48 PM

Thank u KingOfGamesYami.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users