Use instance of IndexOf function to find string position in PowerShell _powershell

Source: Internet
Author: User

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!

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.