powershell - PowerShell 中是否有一种方法可以在不缩短单词的情况下截断字符串

标签 powershell

我一直在四处寻找,但没有找到任何东西。我想截断一个字符串而不缩短一个字。就像摘录。

$string = "This is my string"

9 = "This is m"

理想情况下会喜欢 "This is my"

最佳答案

$string.Substring(0, $string.IndexOf(" ", 9))

应该做你想做的,即它从你给它的字符编号开始,寻找下一个空格,并在那里缩短字符串。

关于powershell - PowerShell 中是否有一种方法可以在不缩短单词的情况下截断字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5257927/

相关文章:

powershell - Cygwin 的交互式 Powershell

powershell - 在Powershell 2.0中无法将 “PasswordNeverExpires”参数设置为true

powershell使用employeeID获取sAMAccount信息

powershell - 我可以将PowerShell 'Start-Job'设置为低优先级吗?

powershell - 如何绕过Chocolatey安装确认?

windows - 为什么 PowerShell 无法识别带引号的参数?

svn - Powershell 和格式表

windows - Powershell where-object 返回代码

sql-server - 如何附加到powershell哈希表值?

powershell - PowerShell ForEach 循环中的内联命令执行