| View previous topic :: View next topic |
| Author |
Message |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Thu Nov 02, 2006 6:21 am Post subject: WLAN file transfer |
|
|
When you download a file with the method in the example, you'll get a server message, followed by the contents of the file. If I want to print only the contents of the file. The contents are separated from server info by a double enter.("\r\n\r\n"). I do this: | Code: |
if string.find(buffer,"\r\n\r\n") then print(string.sub(buffer,string.find(buffer,"\r\n\r\n"))) end |
But it doesn't work. string.find has two outputs, the start and end where it found the "\r\n\r\n". How do I handle this? How can I tell string.sub to use only the first output of find(start position)? And why doesn't it print anything?
I hope I am not too vague _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Thu Nov 02, 2006 12:36 pm Post subject: |
|
|
this should work:
| Code: |
datafile = string.sub(buffer, string.find(buffer, "\r\n\r\n", -1))
filename = "file.txt"
file = io.open(filename, "w")
if file then
file:write(datafile)
file:close()
end
|
_________________ - be2003
blog |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Fri Nov 03, 2006 12:36 am Post subject: |
|
|
I got it working now, but you must leave out -1 in your code _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Fri Nov 03, 2006 12:39 am Post subject: |
|
|
string.find returns 2 values: start of found pattern and end. How can I tell string.sub to use the last value + 1 ? (I'm now using starting value+4 wich is basicly the same, just curious) _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
be2003
Joined: 20 Apr 2006 Posts: 144
|
Posted: Fri Nov 03, 2006 2:25 pm Post subject: |
|
|
i think i put the -1 in the wrong place.... try this....
| Code: |
datafile = string.sub(buffer, (string.find(buffer, "\r\n\r\n"))+4,-1)
filename = "file.txt"
file = io.open(filename, "w")
if file then
file:write(datafile)
file:close()
end
|
i think to do two vlaues you do...(my lua is a little rusty)
| Code: |
outone, outtwo = string.find(buffer,"\r\n\r\n")
|
_________________ - be2003
blog |
|
| Back to top |
|
 |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Sat Nov 04, 2006 9:04 pm Post subject: |
|
|
| be2003 wrote: | i think i put the -1 in the wrong place.... try this....
| Code: |
datafile = string.sub(buffer, (string.find(buffer, "\r\n\r\n"))+4,-1)
filename = "file.txt"
file = io.open(filename, "w")
if file then
file:write(datafile)
file:close()
end
|
|
This Is exactly how I've changed it!
For the second code: should work. I'll try it soon _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
|