I have a string that looks like a phone number. I'm using a lambda to extract an array of char. Then I want to convert this array into a string. This is what I have:
PhoneCandidate = "(123)-321-1234"; //this is just an example of what it could look like
var p = PhoneCandidate.Where(c => char.IsDigit(c)).ToArray();
string PhoneNumber = p.toString();
However, when I run this code, the variable PhoneNumber becomes just "System.Char[]" instead of the values inside the array.
What do I need to change?
Thanks.
Let's take this a whole new direction:
Assuming
p
is achar[]
you can use the following:You can use the
string
constructor that takes achar[]
.probably the best bet is to use the string constructor per (@Adam Robinson) however as an alternative, you can also use
string.Join(string separator,params string[] value)
(MSDN docs here)Try with constructor
res = new string(yourArray);
One of the
string
constructors takes achar[]
: