1.

Solve : Run a command if string has a certain character?

Answer»

I have looked around for this, and could not find anything on it.

Anyways, is it possible to search a string/variable for defined characters, and RUNNING a command if that is true?

For example:

SET string=1234567

^ Nothing would happen



set string=1234A567

^ Program would inform you that the string has something other than a numberHere's a start, it won't identify any particular non-numeric character just that there is a non-numeric character in the string, maybe you could work on this.

Code: [Select]ECHO off
cls
setlocal

Echo %1|FindStr /R "[^0-9]" > nul

If %ERRORLEVEL% EQU 0 (echo result=non-numeric)

You can do it in one LINE

Code: [Select]Echo %1|FindStr /R "[^0-9]" > nul && echo String contained at least 1 non-numeric character Quote from: Salmon Trout on October 29, 2011, 01:29:09 AM

You can do it in one line


Sure, and still turn Echo off and Cls and SetLocal and....whatever else:
Code: [Select]echo off&cls&setlocal&Echo %1|FindStr /R "[^0-9]" > nul&&If %ERRORLEVEL% EQU 0 (echo result=non-numeric)


Discussion

No Comment Found