DOS批处理:去除字符串中的字符在for循环 [英] DOS Batch : remove characters from string in a FOR loop

查看:810
本文介绍了DOS批处理:去除字符串中的字符在for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个TXT文件:

I have a TXT file that contains :

C086002-B3116
C086014-T1234  
C086014-T1325
C086014-T1375" 
C086014-T1374"  

这些字符串包括尾部空格和双引号。

These strings include both trailing whitespaces and double quotes.

我想用一个for循环来删除这些:

I want to remove these using a FOR loop :

for /f %%a in (file.txt) do (
    set str=%%a
    set str=%str: =%
    set str=%str:"=%
)

壳牌窗户被打开,并立即关闭了,并没有什么你在这个操作帮助在弦上做了...谢谢。

The Shell windows is opening and closing down immediately and nothing is done on the strings... Thanks for your help on this operation.

推荐答案

您必须激活在循环变量的多重变化延迟扩展

You have to activate the delayed expansion for multiple change of a variable in a FORloop

这样的:

@echo off
setlocal enabledelayedexpansion
for /f  "delims=" %%a in (file.txt) do (
    set str=%%a
    set str=!str: =!
    set str=!str:"=!
    echo !str!
)

如果您需要的输出中的一个文件:

If you need the ouput in a file :

@echo off
setlocal enabledelayedexpansion
(for /f  "delims=" %%a in (file.txt) do (
    set str=%%a
    set str=!str: =!
    set str=!str:"=!
    echo !str!
)) >output.txt

这篇关于DOS批处理:去除字符串中的字符在for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆