Get the length of the string after changing it, but before it is assigned

Suppose 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 to get the current length $stringif it is not assigned yet?

+4
source share
1 answer

Just assign a string using +=.

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

Source: https://habr.com/ru/post/1670725/


All Articles