当有大写字符时如何拆分文本?
How can I split text when there's an uppercase character?
我正在制作一个批处理文件,我想在其中说“欢迎 <username>
”,但用户名可以是,例如“HiThere”,我想在 space上限所以它就像“你好”。
那么,有没有办法做到这一点?
使用正则表达式识别并在大写字母前添加 SPACE 字符相对容易。 运行 由 cmd
在 Windows 批处理文件 运行 中。如果您使用的是受支持的 Windows 系统,则可以使用 PowerShell。
SET "THESTRING=HiThereMrNiceGuy"
FOR /F "delims=" %%A IN ('powershell -NoLogo -NoProfile -Command ^
"'%THESTRING%' -creplace '(\S)([A-Z])',' '"') DO (SET "NEWSTRING=%%~A")
ECHO NEWSTRING is set to "%NEWSTRING%"
我正在制作一个批处理文件,我想在其中说“欢迎 <username>
”,但用户名可以是,例如“HiThere”,我想在 space上限所以它就像“你好”。
那么,有没有办法做到这一点?
使用正则表达式识别并在大写字母前添加 SPACE 字符相对容易。 运行 由 cmd
在 Windows 批处理文件 运行 中。如果您使用的是受支持的 Windows 系统,则可以使用 PowerShell。
SET "THESTRING=HiThereMrNiceGuy"
FOR /F "delims=" %%A IN ('powershell -NoLogo -NoProfile -Command ^
"'%THESTRING%' -creplace '(\S)([A-Z])',' '"') DO (SET "NEWSTRING=%%~A")
ECHO NEWSTRING is set to "%NEWSTRING%"