-2

Is it possible to store the text of a large flat file(size approximately 10 mb) to a string in vb.net?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • Sure it is. What have you tried? – Mooing Duck Aug 16 '12 at 16:19
  • Yes, it is possible (but 10 MB is not really "large"). Did you try something that didn't work? Maybe you could show us and we could help you get that working. – R. Martinho Fernandes Aug 16 '12 at 16:20
  • Hi Thanks for your responses. I am currently working on a project and am storing the text of large flat files on a string and then creating an array out of that string. i have not faced any problem yet(fingers crossed!!) but just wanted to be sure if it would not pose any problem in the future.Thanks – sunny varghese Aug 16 '12 at 16:24

2 Answers2

3

There is in fact a function in the base class library that can do exactly this: File.ReadAllText

Dim text = File.ReadAllText("path/to/file")
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
  • Thanks Martinho.. i am currently using a stream reader to read the flat file and then creating an array list out of the streamreader and then store array elements to a single string. – sunny varghese Aug 16 '12 at 16:28
3

The maximum size of a string depends on lots of variables and will be different on every machine.

I found a good explanation on this site

"The maximum size of all reference type (like a string) instances is limited by the CLR to 2GB, that means that a string can hold a maximum of ~1G characters. While it's possible to reach that limit when running on a 64 bit OS, you will never be able to create such large strings (or arrays) on a 32 bit OS. The reason is that you won't have that amount of "contiguous" address space available to create the backing store (a char array) for the string."

The accepted answer to this SO question would echo the above explanation

Community
  • 1
  • 1
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143