PowerShell contains function lookup string instance _powershell

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.