Texts with Maximum Length (Part 1)

by Mar 17, 2017

If you want to make sure a text is of given length, here is an easy approach:

$text = 'this is a long text'
$MaxLength = 10

$text.PadRight($MaxLength).Substring(0,$MaxLength)

This code first pads the text in case it is shorter than the maximum length, and then Substring() is cutting off excess text.

Twitter This Tip! ReTweet this Tip!