ReadLine.htm 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>ReadLine$ (filehandle/stream)</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. filehandle/stream = a valid variable set with the OpenFile, ReadFile command, or OpenTCPStream (v1.52+). The value returned is a text string.
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. Once you've opened a disk file (or stream) for reading, use this command to read a whole line of text from a text file or stream. Each line of text is returned as a string variable. This function can be used to read plain text files. <br />
  21. <br />
  22. <br />
  23. Characters are read from the input file until an "end-of-line" mark is found. An "end-of-line" can be a single carriage return (0Dh) or a single linefeed (0Ah) or carriage return followed by a linefeed (0Dh, 0Ah). Reading beyond the end of file does not result in an error, but each value read will be a zero length string. <br />
  24. <br />
  25. <br />
  26. ReadLine$ returns all chars except chr$(13)/chr$(10). <br />
  27. <br />
  28. <br />
  29. Streams can only be used in Blitz Basic v1.52 or greater.
  30. </td>
  31. </tr>
  32. </table>
  33. <h1><a href=../2d_examples/ReadLine.bb>Example</a></h1>
  34. <table>
  35. <tr>
  36. <td>
  37. ; Reading and writing a file using ReadLine$ and WriteLine functions <br />
  38. <br />
  39. ; Initialise some variables for the example <br />
  40. String1$ = "Line 1 is short" <br />
  41. String2$ = "Line 2 is a longer line but they can be much longer" <br />
  42. String3$ = "Line 3 is made up " <br />
  43. String4$ = "of two parts joined together." <br />
  44. <br />
  45. ; Open a file to write to <br />
  46. fileout = WriteFile("mydata.txt") <br />
  47. <br />
  48. ; Write the information to the file <br />
  49. WriteLine( fileout, String1 ) <br />
  50. WriteLine( fileout, String2 ) <br />
  51. WriteLine( fileout, String3 + String4) <br />
  52. WriteLine( fileout, "Just to show you don't have to use variables" ) <br />
  53. <br />
  54. ; Close the file <br />
  55. CloseFile( fileout ) <br />
  56. <br />
  57. ; Open the file to Read <br />
  58. filein = ReadFile("mydata.txt") <br />
  59. <br />
  60. Read1$ = ReadLine$( filein ) <br />
  61. Read2$ = ReadLine$( filein ) <br />
  62. Read3$ = ReadLine$( filein ) <br />
  63. Read4$ = ReadLine$( filein ) <br />
  64. <br />
  65. ; Close the file once reading is finished <br />
  66. CloseFile( filein ) <br />
  67. <br />
  68. Print "Lines of text read from file - mydata.txt " <br />
  69. Print <br />
  70. Print Read1 <br />
  71. Print Read2 <br />
  72. Print Read3 <br />
  73. Print Read4 <br />
  74. <br />
  75. WaitKey()
  76. </td>
  77. </tr>
  78. </table>
  79. <br>
  80. <a target=_top href=../index.htm>Index</a><br>
  81. <br>
  82. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ReadLine&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  83. </html>