louisiana_blues
asked on
How do I mimic a System.IO.Stream, if I have a String, instead of a string stored in a file?
I have a class that is final. I cannot change it. The problem is that the class has a constructor of it's VB, but I don't care if the answer is C# based...it's a library.
Sub New ThisClass(ByVal reader As XMLTextReader)
Here's the issue I need to solve. I do not have the information I want to pass in to this class stored in a file. I have it stored in a string (ie. like a file that's already read in). Is there a way to mimic a System.IO.StreamReader, using an in memory string, instead of a file (which is just pointing to a string anyway?
Since I am desperate for an answer (deadlines. Ack!), I am offering 500 pts to the expert who can help me 'fake' a string by wrapping it into some kind of IO Stream, so that I can instantiate the XMLTextReader class as follows:
Dim sinmemoryfile As String
Dim ostream [some kind of IOStream in memory] = New [some kind of IO.Stream in memory](sinmemoryfile)
Dim oxmlreader As XmlTextReader = New XmlTextReader(ostream (as System.IO.Stream))
Do you understand the dilemma I have? I don't need to read the file in! It's already read (and is fact, never in a file). I do not want to have to save this string to a file and then pass in the file--that's incredibly inefficent and then I'd have to keep track of a ton of files (never mind naming conventions, etc.)
Is there some way to create an System.IO.Stream that uses a string?
Thanks in advance for your expertise!
Sub New ThisClass(ByVal reader As XMLTextReader)
Here's the issue I need to solve. I do not have the information I want to pass in to this class stored in a file. I have it stored in a string (ie. like a file that's already read in). Is there a way to mimic a System.IO.StreamReader, using an in memory string, instead of a file (which is just pointing to a string anyway?
Since I am desperate for an answer (deadlines. Ack!), I am offering 500 pts to the expert who can help me 'fake' a string by wrapping it into some kind of IO Stream, so that I can instantiate the XMLTextReader class as follows:
Dim sinmemoryfile As String
Dim ostream [some kind of IOStream in memory] = New [some kind of IO.Stream in memory](sinmemoryfile)
Dim oxmlreader As XmlTextReader = New XmlTextReader(ostream (as System.IO.Stream))
Do you understand the dilemma I have? I don't need to read the file in! It's already read (and is fact, never in a file). I do not want to have to save this string to a file and then pass in the file--that's incredibly inefficent and then I'd have to keep track of a ton of files (never mind naming conventions, etc.)
Is there some way to create an System.IO.Stream that uses a string?
Thanks in advance for your expertise!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks dude. I will give that a try. If it works, you get the points. Thanks to the others. I was looking for something including code, not a link that I would have read to infer an answer...
I will share the points, but dbaduck will get the most if his/her solution works. Hope that's okay!
Okay, I checked it and it works. You are indeed experts! You all jumped on that question like it was a happy pill. ;-)