A very simple way is to use this regex:
string trimmed = Regex.Match(input,@"^.{1,180}\b").Value;
The only problem is that it may contain trailing spaces. To fix this, we can add a little negative look:
string trimmed = Regex.Match(input,@"^.{1,180}\b(?<!\s)").Value;
That should do the trick.
source share