如何在位置 x 之后在 PowerShell 中找到子字符串的位置? [英] How do I find the position of substring in PowerShell after position x?

查看:38
本文介绍了如何在位置 x 之后在 PowerShell 中找到子字符串的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单的方法可以做到这一点;我找不到任何.我必须逐个字符扫描吗?

Is there a simple way to do so; I can't find any. Am I obliged to scan character by character?

我不想要一个字符串作为返回值,而是一个位置,所以不建议使用 SubString.

I don't want a string as return, but a position so do not suggest SubString.

推荐答案

是的,你可以.IndexOf() 方法具有 重载接受一个 startIndex 参数:

Yes, you can. The IndexOf() method has an overload that takes a startIndex argument:

PS C:\> "WordsWordsWords".IndexOf("Words")
0
PS C:\> "WordsWordsWords".IndexOf("Words", 2)
5

在第二个示例中,我们查找子字符串Words"的索引,该索引从 after 字符索引 2 开始.

In the second example, we look for the index of the substring "Words" starting after character index 2.

这篇关于如何在位置 x 之后在 PowerShell 中找到子字符串的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆