How does a batch process determine that a parameter contains certain strings? _dos/bat

Source: Internet
Author: User

How does a batch process determine that a parameter contains certain strings?

The general situation to determine when the exact match with = =

Copy Code code as follows:

@echo off
If "%1" = = "abc" @echo OK

But how do you write a partial match? For example, when the first three characters in a parameter are "ABC"

Copy Code code as follows:

@echo off
echo%1|findstr "^ABC" >nul
Echo%errorlevel%

The test results are as follows:

C:\>test Xixi
1

C:\>test
1

C:\>test ABCD
0

C:\>test XABCD
1

Thank you very much, but how do I achieve the effect of if else?

Like what

If '%1 ' contains ' abc ' @echo OK
If '%1 ' contains ' def ' @echo NG

Copy Code code as follows:

@echo off
echo%1|findstr "^ABC" >nul
If%errorlevel% equ 0 (
Echo OK
) Else (
Echo Not OK
)

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.