1. 字符串定义
使用set
来定义字符串
@echo off
set string1=Hello
echo %string1%
代码说明:
- 将字符串Hello赋值给string1的变量
2. 字符串拼接
使用 %string1%%string2%
的方式完成字符串的拼接。
@echo off
set string1=Hello
set string2=World
set combined1=%string1% %string2%
set combined2=%string1%,%string2%
set combined3=%string1%%string2%
set combined4=aaa%string1%bbb%string2%ccc
set "combined5=%string1%^&%string2%"
echo %combined1%
echo %combined2%
echo %combined3%
echo %combined4%
echo %combined5%
代码说明:
- 用来连接字符串的字符串,如果包含了特殊字符则需要使用
^
转义,并且需要使用""
括起来,特殊字符包括(但不限于):
符号 作用 @
命令行回显屏蔽符 %
批处理变量引导符 >
重定向符 >>