Powershell格式字符串,带有函数输出

Adi*_*ilZ 2 variables powershell function

嘿家伙我无法弄清楚如何将以下函数(需要输入)转换为变量

 function Convert-ToLetters ([parameter(Mandatory=$true,ValueFromPipeline=$true)][int] $value)  {
   $currVal = $value;
   $returnVal = '';
   while ($currVal -ge 26) {
      $returnVal = [char](($currVal) % 26 + 65) + $returnVal;
      $currVal =  [int][math]::Floor($currVal / 26)
   }
  $returnVal = [char](($currVal) + 64) + $returnVal;

     return $returnVal
  }
Run Code Online (Sandbox Code Playgroud)

此函数的作用是将数字转换为字母.

现在我想要实现的是以某种方式做到这一点:

$convert2letter = Convert-ToLetters()
Run Code Online (Sandbox Code Playgroud)

所以我可以做类似的事情

$WR= "$convert2letter($CValue1)" + "-" + "$convert2letter($CValue2)" + "-" + "3"
Run Code Online (Sandbox Code Playgroud)

但是Powershell不允许我做$ convert2letter

那我该怎么办?

谢谢

Mat*_*att 5

如果没有更多的信息来证明它的合理性,我会考虑而不是:

$WR= "$convert2letter($CValue1)" + "-" + "$convert2letter($CValue2)" + "-" + "3"
Run Code Online (Sandbox Code Playgroud)

你应该这样做:

$WR = "$(Convert-ToLetters $CValue1)-$(Convert-ToLetters $CValue2)-3"
Run Code Online (Sandbox Code Playgroud)

它使用子表达式.或者使用格式运算符

$WR = "{0}-{1}-3" -f (Convert-ToLetters $CValue1), (Convert-ToLetters $CValue2)
Run Code Online (Sandbox Code Playgroud)