I want to substring a variable length string with leading spaces to 25 or less characters. i got it to work but looking for other ways?
... item.LineString.Trim().Substring(0,
item.LineString.Trim().Length > 25 ? 25 : item.LineString.Trim().Length));
I'd use Math.Min:
var trimmed = item.LineString.Trim();
var substring = trimmed.Substring(0, Math.Min(25, trimmed.Length));
You can shorten it with:
item.LineString.Trim().Substring(0, Math.Min(25, item.LineString.Trim().Length));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With