传递多行字符串 [英] Passing around multi-line strings

查看:110
本文介绍了传递多行字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个批处理文件,该文件绕过带有换行符的字符串,但是无法正常工作.字符串的继续作为新命令执行.

I'm trying to create a batch file which passes around a string with line feeds in it but its not working out. The continuation of the string is executed as a new command.

反正有没有对换行进行编码或使之工作?

Is there anyway to encode a line feed or make this work?

推荐答案

您可以使用脱字符号直接创建多行字符串(需要一个空行).

You can create directly multiline strings with the caret (one empty line is required).

setlocal EnableDelayedExpansion
set multiLine=This is a ^

multiline text^

line3
echo !multiLine!

或者您可以先创建一个换行符.

Or you can create first a newline character.

setlocal EnableDelayedExpansion
set LF=^


rem Two empty lines are required
set multiLine=This is a!LF!multiline text!LF!line3
echo !multiLine!

有关其工作原理的解释,请参见解释dos-batch换行符变量hack的工作原理

An explanation how this works can be found at Explain how dos-batch newline variable hack works

这篇关于传递多行字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆