
[英]How to grab a portion of an LDAP string into a variable (Powershell)
[英]portion of powershell variable value to display
我有一个变量,其值为“大苹果”,这就是我在表单上显示的内容。 我想保持变量值不变,但想从中只显示“Apple”。 我不想使用SubString
。 只是以某种方式或任何其他方式通过循环。 可能吗? 怎么做?
$result.content = "Big Apple"
foreach($number in $result.content)
{
$result.content "Apple" //for display
}
如果您知道内容的格式(例如总是两个字符串)以及您想要的部分(例如第二个字符串),那么您可以执行以下操作:
$result.content.split()[1]
如果您不确定字符串中有多少部分,但总是想要最后一个,请执行以下操作:
$result.content.split()[-1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.