让我们说我想做这样的事情:
$string = 'arbitrary string' # << is random
$string = ($string + 'randomstring').Substring(0, [math]::Min(20, $string.lenght) # < doesn't work properly
当尚未分配时,我如何获得$string
的当前长度?
答案 0 :(得分:3)
只需使用+=
分配字符串。
$string = 'arbitrary string' # << is random
$string = ($string += 'randomstring').Substring(0, [math]::MIN(20, $string.Length)) #