[英]remove specific character from a string with batch script
i want to remove only a specific character into a string and only one time. 我只想一次将一个特定字符删除到一个字符串中。 for example, if I have this file: 例如,如果我有此文件:
"1234 + test.txt"
i want to remove "+" character. 我想删除“ +”字符。 my problem is that I don't know how many "+" could be in filename; 我的问题是我不知道文件名中可以有多少个“ +”; by the way, I want to remove only the first: 顺便说一句,我只想删除第一个:
"1234 ++ test + hello + world.txt"
need to be: 需要:
"1234 + test + hello + world.txt"
I need to do this with a bat script. 我需要使用蝙蝠脚本来做到这一点。 I have some problems to use correctly "token,delims" parameters.... 我在正确使用“ token,delims”参数时遇到一些问题。
edit: I've a problem with Edoro's solution. 编辑:我对Edoro的解决方案有疑问。 if filename is "++plus--.txt", %left% is "plus--.txt" and %right% is +plus--.txt 如果filename是“ ++ plus-。txt”,%left%是“ plus-。txt”,%right%是+ plus-。txt
@echo off &setlocal
set "string=1234 ++ test + hello + world.txt"
for /f "delims=+" %%i in ("%string%") do set "left=%%i"
set "right=%string:*+=%"
set "new=%left%%right%"
echo %new%
..output is: ..输出为:
1234 + test + hello + world.txt
通过sed脚本:
echo "1234 + test + hello + world.txt" | sed 's/+//'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.