Easy way to expand
namespace System { public static class Extenders { public static string Join(this string separator, bool removeNullsAndWhiteSpaces, params string[] args) { return removeNullsAndWhiteSpaces ? string.Join(separator, args?.Where(s => !string.IsNullOrWhiteSpace(s))) : string.Join(separator, args); } public static string Join(this string separator, bool removeNullsAndWhiteSpaces, IEnumerable<string> args) { return removeNullsAndWhiteSpaces ? string.Join(separator, args?.Where(s => !string.IsNullOrWhiteSpace(s))) : string.Join(separator, args); } } }
Using:
var str = ".".Join(true, "a", "b", "", "c"); //or var arr = new[] { "a", "b", "", "c" }; str = ".".Join(true, arr);
Adaptabi Oct. 25 '17 at 23:08 on 2017-10-25 23:08
source share