04-14-2011, 10:30 AM
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.
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];
}
}
}
}
}
}