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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top