This article describes a contains function that uses strings in PowerShell to query for the existence of another string in a string.
The Contains () function is inherited from a string object and can be used directly for string lookup judgments. The return value of the Contains () function is a Boolean value, either True or false, which means that the meaning exists or does not exist.
Examples are as follows:
There are 1 in "123"
Copy Code code as follows:
PS c:\users\spaybow> "123". Contains ("1")
True
"12" in "123"
Copy Code code as follows:
PS c:\users\spaybow> "123". Contains ("12")
True
There are 123 in "123"
Copy Code code as follows:
PS c:\users\spaybow> "123". Contains ("123")
True
"13" does not exist in "123"
Copy Code code as follows:
PS c:\users\spaybow> "123". Contains ("13")
False
Because only existence exists, the CONTAINS function cannot position the query string in the queried string. If you need to locate its location, you need to use the IndexOf function, which we will be introducing.
About PowerShell using the contains function to find strings, this article on the introduction of so many, I hope to help you, thank you!