Pages

Aug 13, 2009

How to generate a random unique 5 digit number + C#

Below is the method used to generate random 5 digit number.

public int getRandomID ()

{

Random r = new Random()

return r.Next(10000,99999);

}

The number 10000, 99999 specifies the range.

Aug 12, 2009

How to find and remove Special Characters from a given string. + C#

Here is the method which can remove all the special characters from a given stirng

public string RemoveSpecialChars(string str)
{
string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "-", "_", "(", ")", ":", "", "[", "]" };
for (int i = 0; i < chars.Length; i++)
{
if (str.Contains(chars[i]))
{
str = str.Replace(chars[i], "");
}
}
return str;
}


Thanks
Mukunda