My brain is tired right now and cant come up with a simple solution to this.
var res = error.Split('|');
return String.Format("Name: {0} <br /> Email: {1}", res[0] , res[1]);
If there is no | split then it throws an error what would be a quick and graceful way to just throw in a default “No Name” or pass on it. I only care about positions [0] and [1].
Sample Data
Tom | huntard@123.com
Tom
Tom | huntard@123.com
Tom | huntard@123.com | texas
I need a redbull.
You can use the
ElementAtOrDefault()extension method from theSystem.Linqnamespace combined with the null-coalescing operator (??) for an elegant solution: