How to TRIM a string variable (remove preceding and trailing blank

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My batch program parses a file using %s:~n,m%.
This creates string with trailing blanks that I need to remove.

Does someone know if there is a function similar to vb's TRIM?

Something that returns "ROME" when the city is "ROME ".

I used FOR /f %%m IN ('echo %CITY%') DO SET CITY=%%m, but it has the
disadvantage to return "LOS" when CITY="LOS ANGELES " :-)

Thank you!

Stefano Gatto
Geneva, Switzerland
 
I suggest NOT using the Command Prompt batch language at all but to use the Kixtart
interpreter { http://kixtart.org Kixtart is CareWare }which has greater flexibility and has
an extensive command set, functions and macros library which includes trim().

I think you'll find Kixtart's structure *better* than VBS and the batch file interpreter.

--
Dave




| My batch program parses a file using %s:~n,m%.
| This creates string with trailing blanks that I need to remove.
|
| Does someone know if there is a function similar to vb's TRIM?
|
| Something that returns "ROME" when the city is "ROME ".
|
| I used FOR /f %%m IN ('echo %CITY%') DO SET CITY=%%m, but it has the
| disadvantage to return "LOS" when CITY="LOS ANGELES " :-)
|
| Thank you!
|
| Stefano Gatto
| Geneva, Switzerland
 
Thanks Dave, interesting, but I was asked to enhance a piece of code and use
the batch command interpreter... so I have no choice. I think the main
argument is that the batch interpreter comes along with Windows so there is
no addtl software at all to install.

So I still need an answer to my question if there is someone out there who
could help. I can obviously use %:~n,1% and %:~n,-1% to scan a string and
remove heading and trailing blanks, but wanted to know if there is a better
way...
 
| Thanks Dave, interesting, but I was asked to enhance a piece of code and use
| the batch command interpreter... so I have no choice. I think the main
| argument is that the batch interpreter comes along with Windows so there is
| no addtl software at all to install.
|
| So I still need an answer to my question if there is someone out there who
| could help. I can obviously use %:~n,1% and %:~n,-1% to scan a string and
| remove heading and trailing blanks, but wanted to know if there is a better
| way...
|


I think you need to educate them on the limitations on the BATCH interpreter. As for
installation. One EXE file and a DLL or two copied to the platform. Easily done in a BATCH
file which copies the files to the machine and then runs the script. However, it doesn't
have to be copied to the platform, the EXE and DLL files can be executed from a shared
location.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top