Computing.Net > Forums > Programming > batch programming-Remove Space

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch programming-Remove Space

Reply to Message Icon

Name: industrialist
Date: May 19, 2009 at 19:33:44 Pacific
OS: Windows XP
CPU/Ram: Dual Core2 1.6GHz / 2GB
Product: Don't know / DON'T KNOW
Subcategory: Batch
Comment:

I want to do this
%USERNAME%=Elaine Jack --> ElaineJack (without a space in between two words)

i.e. %USERNAME% is a system variable, user name may be just one word like John, peter and so on. I will make this variable name to create a zip and run another code.

Refer to courtesy help from
But it still fails.

Any help is appreciated. ThanksRef Link --Computing.net

@Echo Off

Set MyVar=AA AAAA
Echo MyVar=[%MyVar%]

Call :TRIM %MyVar%

Echo MyVar=[%MyVar%]
Set MyVar=
GoTo :EOF

:TRIM
Set MyVar=%*
GoTo :EOF



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 19, 2009 at 23:59:48 Pacific
Reply:

I thought I was with you after reading just your first comment. Then it got hazy.

But to simply get a space out of a string:
===========================================

@echo off & setLocal EnableDelayedExpansion

set str=joe smith
echo !str!

for /f "tokens=1-2 delims= " %%a in ("!str!") do (
set var=%%a%%b
)
echo !var!

-----------------------------


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: reno
Date: May 20, 2009 at 11:06:33 Pacific
Reply:

Set MyVar=AA AAAA BB BBBB
set MyVar=%MyVar: =%
echo %MyVar%


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch programming-Remove Space

simple batch program www.computing.net/answers/programming/simple-batch-program/12122.html

Batch program to process all files in folder www.computing.net/answers/programming/batch-program-to-process-all-files-in-folder/19798.html

Advanced batch program www.computing.net/answers/programming/advanced-batch-program/14439.html