tags:

views:

237

answers:

4

C# problem. I have an array

char[] x = {'0','1','2'};
string s = "010120301";

foreach (char c in s)
{
    //how to check if c is in x, a valid char. ????
}

Thanks.

+4  A: 

You could use Array.IndexOf method:

if (Array.IndexOf(x, c) > -1)
{
    // The x array contains the character c
}
Darin Dimitrov
+5  A: 

If I understood correctly, you need to check if c is in x. Then:

if(x.Contains(c)) { ... }
Konamiman
+2  A: 
if (x.Contains(c))
{
 //// Do Something
}

Using .NET 3.0/3.5; you will need a using System.Linq;

Kindness,

Dan

Daniel Elliott
+1  A: 
string input = "A_123000544654654"; 
string pattern = "[0-9]+";
System.Text.RegularExpressions.Regex.IsMatch(input, pattern);
serhio