smart_yuppy <sm************ ****@no-mx.msusenet.com > wrote:
I have done this using C#.NET and collection classes.
Note that there is no reason to pass your hashtable reference *by*
reference - and that a somewhat easier to understand version of
str.Substring(i , 1) is str[i] (as a char, rather than a string -
there's no need to create new strings all over the place). Simpler
still though, you can just use a foreach over the string to get each
character in turn.
You're also completely ignoring the whole point of a hashtable - that
you don't have to step through each element of it. You also don't need
to convert the value in the hashtable to a string and back, and you
don't need to remove the previous value if you use the indexer rather
than the Add method. At that point it's not really worth having a
separate method in the first place.
Here's a briefer version of your code:
private void function(String str)
{
Hashtable h = new Hashtable();
foreach (char c in str)
{
if (h.ContainsKey( c))
{
h[c] = ((int)h[c])+1;
}
else
{
h[c] = 1;
}
}
for (int i=0; i < str.Length; i++)
{
char c = str[i];
if (h[c].Equals(1))
{
textBox2.Text = c.ToString();
break;
}
}
}
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too