CMD - 格式化环境变量

时间:2014-04-07 15:01:46

标签: batch-file cmd

例如,如果%USERNAME% = foo.bar,我想将其更改为FooBar - 删除点和骆驼套管。

到目前为止,我只是试图删除" dot",

@echo off
@setlocal EnableDelayedExpansion

set new=!%USERNAME%:.=!
echo %new%

但这会返回.=。我对Windows批处理脚本(显然)并不是很好,所以提前感谢!

2 个答案:

答案 0 :(得分:3)

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION 

SET "name=foo.bar"

ECHO was:%name%
SET "name=.%name%"
FOR %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET "name=!name:.%%L=.%%L!"
SET "name=%name:.=%"

ECHO now:%name%

GOTO :EOF

答案 1 :(得分:1)

试试这样:

@echo off
set new=%USERNAME:.=%
echo %new%