我正在尝试使用PowerShell修剪字符串。
假设您有以下字符串:
测试/abc测试
我希望‘找到’字符串中的'/a‘,并通过查找下一个空格最终获得"abc“。
这可以用PowerShell实现吗?
发布于 2016-10-28 16:38:56
$postiitonSlashA="Test test test test test test /abc test test test".IndexOf("/a")
$result1="Test test test test test test /abc test test test".Substring($postiitonSlashA)
$postiotnfirstespace=$result1.IndexOf(" ")
$result1.Substring(0, $postiotnfirstespace)
发布于 2016-10-28 05:35:56
假设您的字符串是$testString。这段代码将会工作。它将获取以/a开头的字符,直到下一个空格。
$testString = "Test test test test test test /abc test test test"
$matchString = $testString -match '/a\w*\s' | % {$Matches.Values -replace '/','' -replace'\s',''}
Write-Host $matchString
或者只有一行,不写输出。我只是在前面的示例中编写了输出,以便向您显示结果。
$testString = "Test test test test test test /abc test test test" -match '/a\w*\s' | % {$Matches.Values -replace '/','' -replace'\s',''}
https://stackoverflow.com/questions/40294292
复制相似问题