gpt4 book ai didi

powershell - 使用 Powershell 在字符串中搜索反斜杠

转载 作者:行者123 更新时间:2023-12-02 22:37:02 26 4
gpt4 key购买 nike

我需要搜索字符串中反斜杠的数量以确定一些文件路径参数。我还没有想出一种方法来搜索反斜杠,而 Powershell 认为它是一个逃逸字符。

([regex]::Matches($FilePath, "\" )).count 

或者

$a -match "\"

这些都出现错误“Illegal\at end of pattern”

谢谢!

最佳答案

您可以使用反斜杠转义反斜杠:

[Regex]::Matches($FilePath, "\\").Count

关于powershell - 使用 Powershell 在字符串中搜索反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35497077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com