How do I save a String() during run time.

MiserableMad

Active member
Joined
Feb 2, 2007
Messages
25
Programming Experience
Beginner
I want to be able to put information in a string array. Then during run-time through the same program, to be able to come back and retrieve that same information.
 
For .Net 1.1 I wouldl use the StringCollection:
VB.NET:
Dim scoll As New Specialized.StringCollection
scoll.Add("item1")
scoll.Add("item1")
For Each s As String In scoll
  MsgBox(s)
Next
 
Thanks, now is there a way to save the strings, and use it during runtime at another day? Like it saves the information in the program to be accessed at a different time?
 
Yes, look into using StreamWriter and StreamReader to read/write files, they have ReadLine and WriteLine methods that you can use to read/write one string each line of text file.
 
Yes, look into using StreamWriter and StreamReader to read/write files, they have ReadLine and WriteLine methods that you can use to read/write one string each line of text file.

Does .NET 1.1 have the concept of Preferences/Settings? Could the SPecilaized.StringCollection be stored in there between runs? Its quite simple to say:

Prefs.Default.MyStrings = myStringCOllection
Prefs.Default.Save

Or something.. but i dont know if thats doable in .Net 1.1
 
.Net 1.1 does not have the My.Settings object, but it can serialize. Here's the example writing+reading this collection with serialization method:
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ser [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Xml.Serialization.XmlSerializer([/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](Specialized.StringCollection))
[/SIZE][SIZE=2][COLOR=#008000]'write to file
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] writer [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IO.StreamWriter("review.xml")
ser.Serialize(writer, scoll)
writer.Close()
[/SIZE][SIZE=2][COLOR=#008000]'read from file
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] reader [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IO.StreamReader("review.xml")
scoll = ser.Deserialize(reader)
reader.Close()
[/SIZE]
 
Back
Top