Programming Cat
Programming Cat

Reputation: 65

String Comparison in Batch Not Working

This has been frustrating me for TOO long. It can't be this hard. I've been looking at other people's examples and STILL cannot get two strings to match up in Batch. What am I doing wrong?

SET largeString="c:\programs\test"
SET compareTo="test"
SET smallString=%largeString:~13,4%
if %compareTo%==%smallString% echo YES

So that's literally ALL I'm trying to do. It will never echo YES. I have tried

if "%compareTo%"=="%smallString%"

And

if %compareTo% EQU %smallString%

And

if "%compareTo%" EQU "%smallString%"

I am so frustrated at this x.x Did I miss a space somewhere? Did I add a space somewhere?

Upvotes: 2

Views: 1610

Answers (1)

David Ruhmann
David Ruhmann

Reputation: 11367

Your quotations are a literal part of the largeString and compareTo strings, therefore your sub-string numbers are wrong and the quotations are included in the comparison from the compareTo string.

NOTE: OP updated answer, with new numbers.

Upvotes: 3

Related Questions