IF statement ignore special characters

November 30, 2011 at 19:00:52
Specs: Win7, Intel Core 2 Quad 2.5Ghz / 4GB
I know that ^ stops special characters like & and ? from working in echo.
But how do I disregard them from an IF?

This is what I have.

IF "%i%"=="." Goto :CHANGEFULLSTOP
IF "%i%"=="?" Goto :CHANGEQUESTION

Top 1 works fine as it should. But bottom 2 are special chars and they don't work.
Making it =="^&" Goto doesn't work either.

How to ignore them as commands?

See More: IF statement ignore special characters

Report •

November 30, 2011 at 19:11:03
I think you need to enable delayed expansion. Have a look at this:


Report •

November 30, 2011 at 19:44:16
This works for me in XP, hope it helps.:

set i=%1
set j=&
set k=?

if "%j%"=="%i%" echo equals and
if "%k%"=="%i%" echo equals query

Please come back & tell us if your problem is resolved.

Report •

December 1, 2011 at 05:49:44
I tried it and messed around with the order but still no luck.
Seems it's different in Win7 :/

There has to be a simple solution to this, there must be.
I still need help if anyone else comes along this post.

Edit: and I have enabled delayed expansion already

Report •

Related Solutions

December 1, 2011 at 06:01:05
I'll just leave this here:
Thu 2011.12.01  8.58.57
C:\>set i=?

Thu 2011.12.01  8.59.28
C:\>if "%i%"=="?" @echo Y

Also, I suggest you pick a real scripting language. If you have Win7, Powershell is the hot new thing. You just need to wrap your head around a scripting environment that doesn't run scripts.

How To Ask Questions The Smart Way

Report •

December 1, 2011 at 11:07:19
Cheer Razor. I found out mine works anyway, but it doesn't do exclamation marks for some reason. But that's not too important.

And PowerShell, I've seen that before somewhere, I may try it out thanks :)

Report •

Ask Question