Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#]StringList class
#1
The class is a string array class.
You can add and remove strings in the array called Items.
It can be very useful, when you're working with string arrays, however I would suggest using dicts.

Code:
public class StringList
    {
        public StringList(int Length)
        {
            Items = new string[Length];
        }
        public string[] Items;
        public void Add(string Item)
        {
            for (int i = 0; i < Items.Length; i++)
            {
                if (Items[i] == null)
                {
                    if (!Items.Contains(Item))
                    {
                        Items[i] = Item;
                        i = Items.Length + 1;
                    }
                }
            }
        }
        public void Add(byte[] BytesToDecode, params char[] separator)
        {
            string[] items = Encoding.ASCII.GetString(BytesToDecode).Split(separator);
            for (int y = 0; y < items.Length; y++)
            {
                string Item = items[y];
                for (int i = 0; i < Items.Length; i++)
                {
                    if (Items[i] == null)
                    {
                        if (!Items.Contains(Item))
                        {
                            Items[i] = Item;
                            i = Items.Length + 1;
                        }
                    }
                }
            }
        }
        public void Add(string[] ItemsToAdd)
        {
            for (int y = 0; y < ItemsToAdd.Length; y++)
            {
                for (int i = 0; i < Items.Length; i++)
                {
                    if (Items[i] == null)
                    {
                        if (!Items.Contains(ItemsToAdd[y]))
                        {
                            Items[i] = ItemsToAdd[y];
                            i = Items.Length + 1;
                        }
                    }
                }
            }
        }
        public void Remove(string Item)
        {
            string[] items = new string[Items.Length];
            int y = 0;
            for (int i = 0; i < Items.Length; i++)
            {
                if (Items[i] == Item)
                {
                    Items[i] = null;
                }
                else if (Items[i] != null)
                {
                    if (Items[i].Length > 0)
                    {
                        items[y] = Items[i];
                        y++;
                    }
                }
            }
            Items = new string[Items.Length];
            for (int u = 0; u < Items.Length; u++)
            {
                if (Items[u] == null)
                {
                    if (items[u] != null)
                    {
                        if (items[u].Length > 0)
                        {
                            Items[u] = items[u];
                        }
                    }
                }
            }
        }
    }
Reply


Messages In This Thread
[C#]StringList class - by BaussHacker - 04-14-2011, 10:30 AM
RE: [C#]StringList class - by cfillion - 04-14-2011, 04:52 PM
RE: [C#]StringList class - by BaussHacker - 04-15-2011, 12:56 AM
RE: [C#]StringList class - by KoBE - 04-15-2011, 09:59 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)