Page 1 of 1

How to test for quotes inside conditions

Posted: 23 Aug 2012 15:07
by ®ᴱᵴᴲᴙᴠᴱᴆ
Are there different ways to test for things like quotes in the string...?!?

Code: Select all

@echo off
@setlocal enabledelayedexpansion

set var="
set ret="

if {!var!}=={!ret!} echo.How else can this be tested...w/o using setlocal...

Re: How to test for quotes inside conditions

Posted: 24 Aug 2012 07:12
by Ed Dyreen

Code: Select all

@echo off &setlocal enabledelayedexpansion

call :§hasQuotes ""
call :§hasQuotes "#"
call :§hasQuotes """

pause
exit

:§hasQuotes ( %1 )
:: (
   set "$=_%~1_"

   if /i "!$!" == ^"!$:"=!" (

          set /a $err = 1
   ) else set /a $err = 0

   echo. &set "$"
:: )
exit /b !$err!

Code: Select all


$=__
$err=1

$=_#_
$err=1

$=_"_
$err=0
Druk op een toets om door te gaan. . .