This article describes using the IndexOf function of a string in PowerShell to query if there is another string in a string, and if so, where it is.
The IndexOf function is a static method of a string object that is used to find the position of a string within another string. If the lookup string does not exist in the queried string, the return value is-1. If present, the location of the lookup string is returned, starting at 0.
Here's a look at the example:
"13" does not exist in "123"
Copy Code code as follows:
PS c:\users\spaybow> "123". indexof ("13")
-1
In "123", the position of "1" is 0, which is the starting position.
Copy Code code as follows:
PS c:\users\spaybow> "123". indexof ("1")
0
In "123", the position of "2" is 1, that is, the second position.
Copy Code code as follows:
PS c:\users\spaybow> "123". indexof ("2")
1
In "123", the position of "12" is 0, which is the starting position.
Copy Code code as follows:
PS c:\users\spaybow> "123". indexof ("12")
0
About PowerShell using the IndexOf function to find the string position, this article introduces so many, hope to help you, thank you!