Solved

How do I mimic a System.IO.Stream, if I have a String, instead of a string stored in a file?

Posted on 2007-03-28
4
194 Views
Last Modified: 2013-12-17
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!
0
Comment
Question by:louisiana_blues
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Assisted Solution

by:Babycorn-Starfish
Babycorn-Starfish earned 125 total points
ID: 18812554
what about a memory stream?
0
 
LVL 11

Assisted Solution

by:Babycorn-Starfish
Babycorn-Starfish earned 125 total points
ID: 18812565
0
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 375 total points
ID: 18812568
There is a StringReader class in System.IO that takes a String.
Then you can use the XmlTextReader to get at it like this:

Dim sinmemoryfile as String
Dim ostream as StringReader = New StringReader(sinmemoryfile)
Dim oxmlreader as XmlTextReader = CType(XmlTextReader.Create(ostream), XmlTextReader)

Then use the XmlTextReader. (or in any case you can use the XmlReader class which is what XmlTextReader returns)

Ben.
0
 

Author Comment

by:louisiana_blues
ID: 18812600
Hey dbaduck:

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. ;-)
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question