How do we compare strings which got space and special chars in batch file?
I am trying:
if %DevEnvDir% == "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\"( echo VS2010 )
But it gives an error "Files was unexpected at this time."
I tried:
if "%DevEnvDir%" == "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\"( echo VS2010 )
But it gives an error "The syntax of the command is incorrect."
Any ideas?
Using String. equals() :In Java, string equals() method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true. If any character does not match, then it returns false.
The comparison operators also work on strings. To see if two strings are equal you simply write a boolean expression using the equality operator.
The compareTo() method This method compares two Strings lexicographically. This method returns a negative integer if current String object lexicographically precedes the argument string. a positive integer if current String object lexicographically follows the argument true when the strings are equal.
Just put quotes around the Environment variable (as you have done) :if "%DevEnvDir%" == "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\"
but it's the way you put opening bracket without a space that is confusing it.
Works for me...
C:\if "%gtk_basepath%" == "C:\Program Files\GtkSharp\2.12\" (echo yes) yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With