CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284

    StringCollection Dll

    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];
    Attached Files Attached Files
    WM.

    What about weapons of mass construction?

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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

  3. #3
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    This wasn't meant to be a stringbuilder.... it cannot make strings out of bytes !
    It can only make a collection of strings.
    WM.

    What about weapons of mass construction?

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    Oh ! I got your point !

    Paresh

  5. #5
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    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?
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured