Is it possible to make the stream reader to read a string variable, or a textbox instead of a text file? If yes, how?
Asked
Active
Viewed 5,612 times
2 Answers
6
No but you can use the StringReader
class instead.
StringReader
and StreamReader
provide the same consumable interface and both inherit from TextReader
.

Konrad Rudolph
- 530,221
- 131
- 937
- 1,214
-
is there any alternative for "EndOfStream" in the StringReader? – user2023328 Mar 23 '13 at 10:42
-
@user2023328 No because it *hasn’t got* a stream (it reads from a *string*, not a stream). But you shouldn’t need this function – just read the contents via the high-level functions `Read`, `ReadLine` and `ReadToEnd`. Low-level stream functions like `EndOfStream` are more relevant for byte streams which this isn’t anyway. – Konrad Rudolph Mar 23 '13 at 10:49
0
If you need to create a new IO.Stream from a String or StringBuilder
Dim s As IO.Stream = New IO.MemoryStream(Text.ASCIIEncoding.Default.GetBytes(sb.ToString()))
Some functions are not happy with just a StringReader.

fcm
- 1,247
- 15
- 28