I want to write a simple batch script which checks if the input string has more than 5 chars.
Something like:
SET /P INPUT=Enter your string:
IF %INPUT% > 5 (
ECHO %INPUT% has more than 5 chars
) ELSE (
ECHO %INPUT% has less than 5 chars
)
How I can perform these kind of checks in .bat?
You can look whether there is a character following the fifth with a simple substring operation:
No need to figure out the length of the string if you don’t need the actual number somewhere. Although jeb’s approach to get the length is fairly clever (and exactly the same idea that is used here).