批处理:抓取字符串的第一个字母

时间:2015-01-06 13:56:55

标签: batch-file

目前正在测试一些东西并且如果可以抓取字符串的第一个字母并将其分配给变量那么就会徘徊?

一些上下文/示例:

set USRDIR1==\\SERVER\Users\%username%
if not exist %USRDIR1% mdkir %USRDIR1%

rem // grab first letter from %username% and assign to %firstletter% //

set USDIR2==\\SERVER\Users\%firstletter%\%Username%
if not exist %USRDIR2% mkdir %USRDIR2%

1 个答案:

答案 0 :(得分:3)

set USRDIR1==\\SERVER\Users\%username%
if not exist %USRDIR1% mdkir %USRDIR1%

rem // grab first letter from %username% and assign to %firstletter% //
set firstletter=%username:~0,1%

set USDIR2==\\SERVER\Users\%firstletter%\%Username%
if not exist %USRDIR2% mkdir %USRDIR2%

Check variable substring syntax