Echo在批处理文件中写入尾随空格

时间:2016-05-06 23:50:47

标签: batch-file

使用这个批处理文件,我在输出txt文件的每一行都得到一个尾随空格:

from gimfu import *
class line:
    """creates a line object and defines functions specific to lines """
    def __init__(self, points):
        self.points = points
        self.pointcount = len(points)*2
    def printpoints(self):
        """converts point array in form [(x1,y1),(x2,y1)] to [x1,y1,x2,y2] as nessecary for gimp pdb calls"""
        output=[]
        for point in self.points:
            output.append(point[0])
            output.append(point[1])
        return output
    def draw(self,layer):
        pdb.gimp_pencil(layer,self.pointcount,self.printpoints())

如何删除尾随空格?我希望尽可能避免创建新的批处理文件。

1 个答案:

答案 0 :(得分:3)

%%A=之间的空格包含在您的字符串中。要避免这种情况,您可以使用多行for循环,也可以只在set语句旁边加上引号。

@echo off
setlocal enabledelayedexpansion

for /f "delims==" %%A in (trimlist.txt) do set "string=%%A" & echo !string:,=.!>>trimlist-new.txt