I have been trying to make a program that detects if the string that is entered contains +, -, *, or / and then evaluates it. The problem is that var is always defined whether the string contains the characters or not.
Examples:
Input: not a math command
Output: var is defined (math input
What I wanted: var is not defined
Input:10+10
Output: var is defined (math input
What I wanted: var is defined (math input
Input: ABC123
Output: var is defined (math input
What I wanted: var is not defined
I have adapted my code from this link:
how to check if a parameter (or variable) is numeric in windows batch file
Code:
@echo off
SET "var="
set /p "COMMAND=Enter command>"
for /f "delims=^+-^*/" %%i in ("%COMMAND%") do set "var=%%i"
if not defined var (
echo var not defined
) else (
echo var is defined (math input)
)
pause