Limiting Maximum String Length

by Dec 23, 2014

All Versions

To make sure output text is not excessively long, you can use logic like this to shorten text that is longer than a given maximum length:

if ($text.Length -gt $MaxLength)
{
  $text.Substring(0,$MaxLength) + '...'
}
else
{
  $text
} 

Twitter This Tip! ReTweet this Tip!