473,763 Members | 6,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

saving string array to disk

I have a string array, which I need to save to a file.
The array may grow to thousands of elements.
My question is what is the fastest way to save it as text file?
The StreamWriter accepts String as parameter, but converting the array
to a single string takes a lot of time (by using a For loop and
concatenating the string).
How this can be done faster?

P.S. Every element of string array should be in separate row of the
file. So the CrLf should be added to each element of array.

Nov 21 '05 #1
3 1756
Nikolay,

Why not use the writeline of the StreamWriter in a loop through the array,
including the flush and the close not more than 8 lines of code in my
opinion.

Cor
Nov 21 '05 #2
that will do the trick
thanks Cor
it wasn't obvious to me at fitst look
newbie things, what can i say ;-)

Nov 21 '05 #3
"Nikolay Petrov" <jo******@mail. bg> schrieb:
I have a string array, which I need to save to a file.
The array may grow to thousands of elements.
My question is what is the fastest way to save it as text file?


I don't know if it's the fastest way, but I prefer something like this:

\\\
' Write data to file.
FileOpen(1, "C:\Foo.txt ", OpenMode.Output )
Dim astr() As String = {"Hello", "World", "Bla"}
For Each t As String In astr
PrintLine(1, t)
Next t
FileClose(1)

' Read data from file.
FileOpen(1, "C:\Foo.txt ", OpenMode.Input)
Dim s As String
Do Until EOF(1)
LineInput(1, s)
MsgBox(s)
Loop
FileClose(1)
///

Alternatively you can loop through the array and use a 'StreamWriter'' s
'WriteLine' method to add a line to the file.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

138
6580
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the yeah,-that's-non-obvious dept. theodp writes "As if there weren't enough dodgy patents, here's an excerpt from one granted to Microsoft Tuesday for a 'Method and apparatus for displaying information regarding stored data in a gaming system': 'When saving a game,...
2
2296
by: eth0 | last post by:
I hate to ask like this as I normally like to work things out for myself, but I am running out of ideas....and hair !!! I am writing a stock inventory program using structures. The program data is initially populated by hand, and then there is an option to save the array of structures to disk. If the program is exited, the data will need to be inserted back into the program, hence the load function.
6
3293
by: Vijay | last post by:
I need to generate HTML files based on the some codes. One HTML file per code. I have the link (ex:http://123.234.345.456/WebPages/GetTestData.aspx?SomeCode=25), by passing the code as parameter I will get the page displayed. But I don't want to display it, instead save those files in one of the network directories that can be accessed by our third party vended web based application. How can I do this accessing and saving HTML files a...
3
2362
by: Mark | last post by:
Hi, I have put together a script in C# that takes a text file, then streams it into a SQLServer database. What I am trying to do now is create another script that does the exact opposite: selects a file in the database, extracts it then saves it to a disk file. This is pretty straightforward to do in VBScript, however I'm having problems getting it to work in C#. Can anyone help?
1
1834
by: Hexman | last post by:
Code below ---- I'm trying to save some specific web pages to disk as text files. I searched the Internet and found a basic example which I changed to fit my needs. I tested it out first on a single URL and it worked fine. Now when I incorporate an array of URL's, it fails to work. The first "responseFromServer" properly retrieves and displays "http://finance.yahoo.com" (or any other valid URL for the first webrequest.create), but when I...
4
6724
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
5
1909
by: Keith G | last post by:
VS2003 using VB.Net I want to be able to save drawing path data in a database. If I store the Points array for each GraphicsPath I can then reproduce (in this case) filled polygons at run time. The user will create the polygons initially. The number of points in the polygons will vary so I only want to save this data in one field (rectangles would have been a lot easier). The only way I can think of doing this is by saving the points...
6
3366
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to a user without saving it to the disk first. Obviously saving the file first and streaming it afterwards is fairly easy to do, but it relies on disk write permissions on the server and you'd have to make sure the file was removed afterwards.
3
2469
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly the binary data for the file. I can sucessfully take the files out of the databse again and display them in a data grid. I would like to resize the submitted file to a fixed size (say 180 x 120) before I upload it to the database and do this without...
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.