string regex = @"{ Engineer = (?<Name>.*), HandHeldAvailability";
string input = "{ Engineer = CARL HARRISON, HandHeldAvailability = H, HASHHT = True, HHTSTATUS = }";
string engineerName = "";
Match match = Regex.Match(input, regex);
if(match.Success && match.Groups["Name"] != null)
{
engineerName = match.Groups["Name"].Value;
}
A Regex allows you to verify that the input string matches (Otherwise match.Success will be false) and allows to easily change it in case the input format changes. You can also match the other parts easily as well.
Edit: If you call this function a lot (i.e. in a loop), then you can also compile the Regex:
public class YourDataClass {
private static Regex regex = new Regex(@"{ Engineer = (?<Name>.*), HandHeldAvailability", RegexOptions.Compiled);
public string GetNameFromInput(string input) {
var result = string.Empty;
Match match = regex.Match(input);
if(match.Success && match.Groups["Name"] != null)
{
result = match.Groups["Name"].Value;
}
return result;
}
}