【问题标题】:How do I make **pure** custom batch commands? [closed]如何制作 **pure** 自定义批处理命令? [关闭]
【发布时间】:2022-01-04 12:55:34
【问题描述】:

我所说的“纯”是指,我已经知道如何制作简单的自定义命令,例如

set /p command=
if "command"="Hello" goto print

:print 
echo World

我想做类似的东西

set /p command=
if "command" starts with "/" goto print

:print 
echo "%command%" without "/"

【问题讨论】:

  • 这能回答你的问题吗? What is the best way to do a substring in a batch file? 具体来说,您可以对第一个字符使用%string:~0,1%,对字符串的其余部分使用%string:~1%
  • 复杂批处理对我来说太混乱了。有没有更简单的方法,或者你能给我代码吗?
  • 它的代码。

标签: batch-file cmd


【解决方案1】:

奇怪的单词选择

“纯”是您输入的内容,非纯是您输出的内容

试试这个并掺假以适应。

echo off
setlocal enableextensions enabledelayedexpansion

echo enter Input with /
set /p "input="

echo Current input is: !input!
echo "!input:~0!"
echo "!input:~1!"
echo "!input:~0,1!"

if "!input:~0,1!" == "/" (
    set input=!input:~1,-1!
)

echo New input is: !input!

结果

enter Input with /
/hello
Current input is: /hello
"/hello"
"hello"
"/"
New input is: hell

【讨论】:

    猜你喜欢
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 2017-11-10
    • 1970-01-01
    相关资源
    最近更新 更多