Hi Annie!
Try this.
string strInput = " X ";
string pattern = "0,4,6,8,11";
string place = strInput.IndexOf("X").ToString();
string[] positions = pattern.Split(",");
var result = positions.Select((s, i) => new { Pos = i, Str = s })
.Where(o => o.Str == place)
.FirstOrDefault();
if (result != null)
{
var output = result.Pos;
}
EDIT: This solution is much more succinct, but note that it requires the input to always be valid, so you might want to do some initial checking.
string strInput = " X ";
string pattern = "0,4,6,8,11";
int place = strInput.IndexOf("X");
var positions = pattern.Split(",").Select(s => int.Parse(s));
int result = positions.TakeWhile((p, i) => p != place)
.Count();