Yes, just use single quote marks without the parse call. '+'
You can also call ToCharArray() on a full string.
private static char[] CharArray1 = { '+', '(', ')', '-', ' ' };
private static char[] CharArray2 = "+()- ".ToCharArray();
It looks like you're going to parse a phone number with an array like that, so I
made a practical example (with something extra):
using System;
using System.Text.RegularExpressions;
namespace DW_421823_CS_CON
{
class Program
{
private static char[] CharArray1 = { '+', '(', ')', '-', ' ' };
private static char[] CharArray2 = "+()- ".ToCharArray();
static void Main(string[] args)
{
string strPhoneNumber = "+1-(913) 555-1212";
Console.WriteLine(string.Join("", strPhoneNumber.Split(CharArray1, StringSplitOptions.RemoveEmptyEntries)));
Console.WriteLine(string.Join("", strPhoneNumber.Split(CharArray2, StringSplitOptions.RemoveEmptyEntries)));
Console.WriteLine(string.Join("", strPhoneNumber.Split("+()- ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)));
Console.WriteLine(Regex.Replace(strPhoneNumber, "[^0-9]", ""));/*completely different*/
}
}
}
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
You can also treat a String as a character array, so
String charArray = "()+- ";
foreach (Char c in charArray) {
...
Is perfectly valid
Momerath
Senior Poster
3,728 posts since Aug 2010
Reputation Points: 1,322
Solved Threads: 624
Skill Endorsements: 13
Question Answered as of 1 Year Ago by
thines01
and
Momerath