4

Before I ask I just want to say that I HAVE looked this up, and I just can't figure it out.
So I've got a web call returning an incredibly long string of text that I need to split up. I want to use textfieldparser but I don't want to save this string as a file and textfieldparser seems to be all about files or... streams and I don't understand streams. So how would I feed a string into this? Can I convert it to a stream? I realize this is probably super simple so I apologize for my ignorance.

Thank you very much for your help!

user1695610
  • 41
  • 1
  • 2

1 Answers1

11

Textfieldparser has a constructor that takes a TextReader. Have you tried something like this:

Dim t As New FileIO.TextFieldParser(New System.IO.StringReader("thestringinside"))

You might also look on www.filehelpers.net (have never tried myself, but looks promising - I am in no way affiliated!) because the engine also supports a ReadString method

Marcos Meli
  • 3,468
  • 24
  • 29
igrimpe
  • 1,775
  • 11
  • 12
  • @Tim Schmelter: you might be right, but I can't see which unmanaged ressource is used here and should be freed immediately? And I am a fan of Jeffrey Richter's "Dispose? Dont! (normally)" attitude. And calling dispose (through _using_) doesnt free the memory (allocated for the string) anyway. – igrimpe Nov 17 '12 at 00:11
  • 1
    Both, the `TextReader` and the `TextFieldParser` implement `IDisposable`. I guess not just for fun ;) – Tim Schmelter Nov 17 '12 at 00:13
  • @Tim Schmelter: Have you ever checked what the dispose methods on these two classes do? Gee, I like Reflector ;) Dispose on the TFP only calls close/dispose on the "stream" (which is a Stringreader). Dispose(boolean) on TextReader is an empty method. So HOW can it be usefull to call it?? – igrimpe Nov 17 '12 at 00:28
  • Sorry: Dispose in STRINGreader sets the underlying string to NULL. Do you always set any string you use to NULL? It doesn't free any mem before the GC runs, so whats the benefit? – igrimpe Nov 17 '12 at 00:35
  • 1
    It just sets the underlying string of the `StringReader` to null, not the referenced string. That's useful to allow the GC to deallocate the string if the original string is out of scope or null. Have a look here: [Is it ok not to dispose a StringReader?](http://stackoverflow.com/questions/3996452/is-it-ok-not-to-dispose-a-memorystream-stringreader) – Tim Schmelter Nov 17 '12 at 00:43