Click to See Complete Forum and Search --> : StringCollection Dll


WillemM
December 30th, 2002, 12:41 AM
I wrote a DLL file, that contains a StringCollection.
If you add a reference to this file, the StringCollection Class will become aviable in the System.Collections namespace !

You can use it like this:

private System.Collections.StringCollection strs;

public void Test()
{
strs = new System.Collections.StringCollection();

strs.LoadFromFile(@"c:\test.txt");
}

The following functions are defined:

Add(string text)
Remove(int index)

And ofcourse you can get/set items like this: strs[x] = "somestring"; somestring = strs[x];

pareshgh
January 2nd, 2003, 07:41 PM
why to write string collection when stringbuilder is already there.

check ouT VS.NET help for
[1]

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemtextstringbuildermemberstopic.htm

WillemM
January 3rd, 2003, 01:48 AM
This wasn't meant to be a stringbuilder.... it cannot make strings out of bytes !
It can only make a collection of strings.

pareshgh
January 6th, 2003, 11:49 AM
Oh ! I got your point !

Paresh

MartinL
January 6th, 2003, 12:27 PM
I think, I miss your point... What do you want to do by that code???

There is ArrayList class which is container and you can use it to store string objects. Or if you need other container, there is Hashtable class which is something as map...

If you need to make strings from the bytes, why don't use

System.Text.Encoding.ASCII.GetBytes(byte[] bytes, int index, int count);

function???

If you need to read the file and parse it into the lines, why don't use StreamReader class and String.Split function?

StreamReader sr = new StreamReader("file.dat");
ArrayList arr = new ArrayList(sr.ReadToEnd().Replace("\r\n", "\n").Split('\n'));

foreach (string s in arr)
{
// iterate for all lines in the file file.dat... the line is in the s variable...
}


Martin