- 1 year ago
Command line how to search a string into a %% variable
To search for a string within a %%
variable in a command-line script, you can use the findstr
command. Here's an example of how to do it:
batch@echo off
set variable=Hello, world!
echo %variable% | findstr "world"
In this example, we have a variable named variable
that contains the string "Hello, world!". We use the echo
command to output the value of the variable and then pipe it (|
) to the findstr
command. The findstr
command searches for the specified string ("world" in this case) within the input text.
If the specified string is found in the variable's value, findstr
will output the matching line. If it is not found, no output will be generated.
You can modify the example to suit your needs by replacing variable
with your actual variable name and changing the search string to your desired value.
Note that the findstr
command performs a case-insensitive search by default. If you want a case-sensitive search, you can use the /C
option with the search string, like this: echo %variable% | findstr /C:"World"
.