Kuya,
If you have the phone numbers hard coded, I would suggest the
following
string[] astrNumbers = {"231-3423", "453-1234", "231-3473",
"231-3474" }
Doing it this way will prevent from having to split the string before
selecting the random number. But if not, I would split the string
this way:
string strNumbers = @"\111-3423/\222-1234/\333-3473/\444-3474/";
string[] astrNumbers;
string strOut = "";
Random rndGenerator = new Random();
int intIndex;
// Remove the first and last chars
strNumbers = strNumbers.Remove( 0 , 1 );
strNumbers = strNumbers.Remove( strNumbers.Length - 1, 1 );
// Replace the double char delimiter with a single
strNumbers = strNumbers.Replace( @"/\", "," );
// Split the numbers into the array
astrNumbers = strNumbers.Split( new char[] { ',' } );
// Make sure you have at least one
if ( astrNumbers.Length > 0 )
{
// Using Next may not be random enough
// you may want to use the NextDouble till
// it's with in range of the array
// Randomly pick an array element
intIndex = rndGenerator.Next( astrNumbers.Length );
// Set the random element to return
strOut = astrNumbers[ intIndex ];
}
Console.WriteLine( "Number selected = " + strOut );
// Return the value
return strOut;
Hope this helps,
Glen Jones MCSD