让用户输入一个大写的第一个字母一个批处理脚本 [英] Make the first letter of user input a capital in a batch script
问题描述
这是批处理脚本我用来做文件夹一个新的客户端:
This is the batch script I use to make the folders for a new client:
@ECHO OFF
SET /p clientLast=Enter Client's Last Name:
SET /p clientFirst=Enter Client's First Name:
ECHO Making Folders...
MKDIR "%clientLast%, %clientFirst%"
MKDIR "%clientLast%, %clientFirst%"\Budget
MKDIR "%clientLast%, %clientFirst%"\"Business Registration"
MKDIR "%clientLast%, %clientFirst%"\Correspondence
MKDIR "%clientLast%, %clientFirst%"\"Financial Info"
MKDIR "%clientLast%, %clientFirst%"\Forms
MKDIR "%clientLast%, %clientFirst%"\Illustrations
MKDIR "%clientLast%, %clientFirst%"\"Loans & Investments"
MKDIR "%clientLast%, %clientFirst%"\"Personal Info"
MKDIR "%clientLast%, %clientFirst%"\Recommendations
MKDIR "%clientLast%, %clientFirst%"\"Tax Misc"
TREE "%clientLast%, %clientFirst%"
ECHO DONE~~~~~~~~~~~~~~~
PAUSE
我希望能够加入到自动大写每个单词的第一个字母的能力。
I want to be able to add the ability to automatically uppercase the first letter of each word.
我找到了一种方法用在它前面的空间与它的资本,它看起来像更换每一个字母做到这一点:
I found a way to do it by replacing every letter with a space in front of it with it's capital, which looks something like:
FOR %%i IN ("a=A" " b= B" " c= C" " d= D" " e= E" " f= F" " g= G" " h= H" " i= I" " j= J" " k= K" " l= L" " m= M" " n= N" " o= O" " p= P" " q= Q" " r= R" " s= S" " t= T" " u= U" " v= V" " w= W" " x= X" " y= Y" " z= Z") DO CALL SET "%1=%%%1:%%~i%%"
但是,这并不大写第一个字...
But this does not capitalize the first word...
任何想法?
推荐答案
或用纯批...
@echo off
setlocal EnableDelayedExpansion
call :FirstUp result hello
echo !result!
call :FirstUp result abc
echo !result!
call :FirstUp result zynx
echo !result!
goto :eof
:FirstUp
setlocal EnableDelayedExpansion
set "temp=%~2"
set "helper=##AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ"
set "first=!helper:*%temp:~0,1%=!"
set "first=!first:~0,1!"
if "!first!"=="#" set "first=!temp:~0,1!"
set "temp=!first!!temp:~1!"
(
endlocal
set "result=%temp%"
goto :eof
)
功能:FirstUp使用搜索的字符串帮手与VAR%的第一个字符的绝招:* X =%语法
The function :FirstUp use the trick of searching for the first character in the helper string with the %var:*x=% syntax.
这将删除第一次出现之前的所有字符(因此我加倍的所有字符)
所以,首先你有单词VOX,VWWXXYYZZ,那么我干脆取%的第一个字符一个%,以获得资金和追加原始字符串的其余部分没有第一个字符后。
This removes all chars before the first occurrence (therefore I double all chars) So, in first you got for the word "vox", "VWWXXYYZZ", then I simply take the first char of %first% to get the capital and append the rest of the original string without after the first char.
这篇关于让用户输入一个大写的第一个字母一个批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!