A
Arpan
The contents of a text file are as follows:
The Quick Brown
Fox Jumped Over
The Lazy Dog.
Note that there isn't any space at the end of each of the 3 lines.
Now when I do this:
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim arrString(10) As Char
Dim strmReader As StreamReader
strmReader = New StreamReader(Server.MapPath("StreamReader.txt"))
strmReader.Read(arrString, 4, 8)
Response.Write("Array: " & arrString)
End Sub
ASP.NET generates the following error:
Offset and length were out of bounds for the array or count is greater
than the number of elements from index to the end of the source
collection.
pointing to the following line:
strmReader.Read(arrString, 4, 8)
But if I replace the offending line with this:
strmReader.Read(arrString, 4, 7)
i.e. change the last parameter of the Read method from 8 to 7, then the
Response.Write outputs the following in the browser:
Array: The Qui
Can someone please explain me why does the Read line in the first case
generate the error?
Secondly, if I replace the Response.Write line shown above with
Response.Write(arrString)
i.e. get rid of the string within the double quotes (preceding the
variable arrString) in the Response.Write line, then the
Response.Write(arrString) line doesn't generate any output in the
browser. Why so?
Thanks,
Arpan
The Quick Brown
Fox Jumped Over
The Lazy Dog.
Note that there isn't any space at the end of each of the 3 lines.
Now when I do this:
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim arrString(10) As Char
Dim strmReader As StreamReader
strmReader = New StreamReader(Server.MapPath("StreamReader.txt"))
strmReader.Read(arrString, 4, 8)
Response.Write("Array: " & arrString)
End Sub
ASP.NET generates the following error:
Offset and length were out of bounds for the array or count is greater
than the number of elements from index to the end of the source
collection.
pointing to the following line:
strmReader.Read(arrString, 4, 8)
But if I replace the offending line with this:
strmReader.Read(arrString, 4, 7)
i.e. change the last parameter of the Read method from 8 to 7, then the
Response.Write outputs the following in the browser:
Array: The Qui
Can someone please explain me why does the Read line in the first case
generate the error?
Secondly, if I replace the Response.Write line shown above with
Response.Write(arrString)
i.e. get rid of the string within the double quotes (preceding the
variable arrString) in the Response.Write line, then the
Response.Write(arrString) line doesn't generate any output in the
browser. Why so?
Thanks,
Arpan