I have a helper method to clean up a string and remove pieces that I will be generating again. (defined by the "SpecialKey" Constants) but I've never been real happy with the code. Although I find it easy to read adding more keys doesn't always seem so clean.
protected static System.String[] GetStringParts(System.String stringValue)
{
System.String[] stringParts = stringValue.Split('!');
System.Func<System.String, System.Boolean> isConstKey = (System.String key) =>
{
return !System.String.IsNullOrWhiteSpace(key) && (
key.StartsWith(MyUtility.SpecialStringKey1) ||
key.StartsWith(MyUtility.SpecialStringKey2) ||
key.StartsWith(MyUtility.SpecialStringKey3) ||
key.StartsWith(MyUtility.SpecialStringKey4)
);
};
return stringParts.Where(key => !isConstKey(key)).ToArray();
}
I have removed specific names and such. I don't usually go by the convention SpecialKey1/2 etc
I'd like any pointers on performance or readability. This code gets hit often but in the last two years has only been changed once (maybe twice).