Simple String Problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rana
Posts: 3
Joined: 10 Mar 2020 08:25

Simple String Problem

#1 Post by rana » 10 Mar 2020 23:34

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.. :( :(
Attachments
image 2.PNG
image 2.PNG (39.4 KiB) Viewed 340 times

jeb
Expert
Posts: 950
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Simple String Problem

#2 Post by jeb » 11 Mar 2020 02:59

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

rana
Posts: 3
Joined: 10 Mar 2020 08:25

Re: Simple String Problem

#3 Post by rana » 11 Mar 2020 04:27

Thank You jeb , :D :D , this forum is awesome

Post Reply