How to test for quotes inside conditions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
®ᴱᵴᴲᴙᴠᴱᴆ
Posts: 6
Joined: 23 Aug 2012 10:17

How to test for quotes inside conditions

#1 Post by ®ᴱᵴᴲᴙᴠᴱᴆ » 23 Aug 2012 15:07

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...

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How to test for quotes inside conditions

#2 Post by Ed Dyreen » 24 Aug 2012 07:12

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. . .

Post Reply