Skip to content

Instantly share code, notes, and snippets.

@DTTerastar
Created October 11, 2013 19:14
Show Gist options
  • Save DTTerastar/6940423 to your computer and use it in GitHub Desktop.
Save DTTerastar/6940423 to your computer and use it in GitHub Desktop.
Split and trim a string. Does not return empty strings.
public static IEnumerable<string> SplitTrim(this string input, params char[] separator)
{
if (input == null) throw new ArgumentNullException("input");
string[] strings = input.Trim().Split(separator);
foreach (var s in strings)
{
string trimmed = s.Trim();
if (!String.IsNullOrWhiteSpace(trimmed))
yield return trimmed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment