Page 1 of 1

Simple String Problem

Posted: 10 Mar 2020 23:34
by rana

Code: Select all

@echo off
set string=Hello
set ab = Batch
set b = Programming
if [%string%]==[] echo "String is empty"
if [%string%] NEQ [] echo String is %string%
echo %ab% %b% 
The code should print out

Code: Select all

String is Hello
Batch Programming


... but instead it is printing out something else... i am attaching an image please have a look.. :( :(

Re: Simple String Problem

Posted: 11 Mar 2020 02:59
by jeb
Hi rana,

it's a problem of your code formatting.
In batch you can't use spaces in a SET expression, without side effects.

The correct syntax is

Code: Select all

SET var=content
or even better, to protect against invisible trailing white spaces
SET "var=content"
You used set ab = Batch, this sets a variable with the name ab<space> to the content <space>Batch

Re: Simple String Problem

Posted: 11 Mar 2020 04:27
by rana
Thank You jeb , :D :D , this forum is awesome