Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
要显示的powershell变量值部分_Powershell - Fatal编程技术网

要显示的powershell变量值部分

要显示的powershell变量值部分,powershell,Powershell,我有一个变量,它的值是“大苹果”,这就是我在表单上显示的内容。我想保持变量值的原样,但只想显示“Apple”。 我不想使用子字符串。只是以某种方式通过循环或任何其他方式。可能吗?怎么做 $result.content = "Big Apple" foreach($number in $result.content) { $result.content "Apple" //for display } 如果您知道内容的格式(例如,始终是两个字符串)以及您想要的部分(例如,第二个字符串),

我有一个变量,它的值是“大苹果”,这就是我在表单上显示的内容。我想保持变量值的原样,但只想显示“Apple”。 我不想使用
子字符串
。只是以某种方式通过循环或任何其他方式。可能吗?怎么做

$result.content = "Big Apple"
foreach($number in $result.content)
{
    $result.content "Apple"  //for display
}

如果您知道内容的格式(例如,始终是两个字符串)以及您想要的部分(例如,第二个字符串),则可以执行以下操作:

$result.content.split()[1]

如果您不确定字符串中有多少个部分,但总是想要最后一个,请执行以下操作:


$result.content.split()?如果您知道内容的格式(例如总是两个字符串)以及您想要的部分(例如第二个字符串),那么您可以这样做:
$result.content.split()。欢迎接受:-)