You could use the
String.Split
method or a
regular expression.
If you were to go for using
Split
something like this might do the trick for you;
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
public static class MyExtensions {
private static readonly IEnumerable<string> Delimiters = new[] { ">=", "<=", "!=", ">", "<", "=" };
public static string GetVariable(this string expression) {
if (Delimiters.Any(expression.Contains)) {
var delimiter = Delimiters.Where(expression.Contains).First();
return expression.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries).First();
}
return null;
}
}
class Program {
static void Main(string[] args) {
var input = new[]
{
"EndMarket=100",
"EndMarket<200",
"EndMarket>300",
"EndMarket!=300"
};
foreach (var s in input) {
Console.WriteLine("{0}: {1}", s, s.GetVariable());
}
}
}
}
Hope this helps,
Fredrik