Computing.Net > Forums > Programming > DOS Batch: Remove Trailing 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.

DOS Batch: Remove Trailing Space

Reply to Message Icon

Name: jimrockford
Date: January 23, 2004 at 08:39:23 Pacific
OS: Windows XP
CPU/Ram: P4 2.6Ghz/512Mb
Comment:

Is there an easy way to remove trailing space characters from the contents of a variable? I want to do it using straight DOS commands. The number of trailing spaces will vary but the variable will always end with "WGM".

Eg: "92CS WGM______" becomes "92CS WGM"

Where _ is a space.




Sponsored Link
Ads by Google

Response Number 1
Name: Infinite Recursion
Date: January 23, 2004 at 10:43:22 Pacific
Reply:

I'm not sure how to do this in just DOS, so you may want to ask this question in the DOS forum.

However, if you want to write a very small block of code... most languages have a Trim() that will do just what you need.

LTrim(" helloworld") = "helloworld"
RTrim("helloworld ") = "helloworld"
Trim(" helloworld ") = "helloworld"

IR


0

Response Number 2
Name: IVO
Date: January 25, 2004 at 09:18:54 Pacific
Reply:

If you are still interested, the following sample batch does what you want:
---
@Echo Off

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

Call :TRIM %MyVar%

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

:TRIM
Set MyVar=%*
GoTo :EOF
-----
where the initial setting of MyVar ends with trailing balnks that are removed by the internal subroutine :TRIM (that is all you need to get your goal).

The :EOF label must not be declared explicitly as it is the standard return point in NT-kernel based scripts.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


array manipulation C++ Event Handling



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: DOS Batch: Remove Trailing Space

del blank lines, remove white space www.computing.net/answers/programming/del-blank-lines-remove-white-space/15304.html

Batch File To Remove Certain Lines2 www.computing.net/answers/programming/batch-file-to-remove-certain-lines2/17237.html

batch processing text files. www.computing.net/answers/programming/batch-processing-text-files/15280.html