Advanced String Manipulation (C#)

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

I would like to randomly output phone numbers seperated by \ and / from a string.
s = "\231-3423/\453-1234/\231-3473/\231-3474/"

//c sharp code
private string GetPhoneNum()
{
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
//randomly pick a phone num from string.

n = randomNum;
return n;//ie. 453-1234
}

Thanks
 
An idea could be to use the Split method of String (using '\' as separator)
and then to randomly take one element

José
 
Hi,

You could use Regex.Split method to split string by "/\" and then use Random
class to pick random string.
 
Back
Top