4c74356b41
4c74356b41

Reputation: 72171

Get string length after it has changed but before its assigned

Lets say I want to do something like this:

$string = 'arbitrary string' # << is random
$string = ($string + 'randomstring').Substring(0, [math]::Min(20, $string.lenght) # < doesn't work properly

How do I get current length of $string, when it is not yet assigned?

Upvotes: 4

Views: 43

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58971

Just assign the string using +=.

$string = 'arbitrary string' # << is random
$string = ($string += 'randomstring').Substring(0, [math]::MIN(20, $string.Length)) #

Upvotes: 3

Related Questions