使用批处理生成 html .. 转义引号

Posted

技术标签:

【中文标题】使用批处理生成 html .. 转义引号【英文标题】:Generating html with batch .. escape quotes 【发布时间】:2011-12-18 01:04:51 【问题描述】:

这应该是生成具有不同文件的网络文档的层次结构,这是因为我很懒我做了这个。

@echo off
echo.
echo This program will generate the base folder for a new website .. .
pause
md folders
echo >  folders/default.html  "<html> /* More content */ </html>"
echo >  folders/style.css " /* All the standards i always use */ "
echo >  folders/javascript.js " /* All the standards i always use */ "
echo.
exit

它也有效,但问题是,我无法删除/转义引号,但这会让人歇斯底里。

我尝试了很多不同的东西。使用类型更改回声,我尝试了可以​​在 www 等上找到的不同转义选项,但引号仍然存在。

【问题讨论】:

Escape angle brackets in a Windows command prompt的可能重复 【参考方案1】:

您需要使用插入符号 ^ 转义所有 CMD 保留字符 < > | ^ ( )&

几个cmets

    如果保留字符在引号内,请不要转义它们 如果 ( and ) 不在 IF 或 FOR 或其他括号块内,则不需要转义。

一个更完整的例子是

echo ^<!DOCTYPE HTML PUBLIC^> >index.html
echo ^<html^> >>index.html
echo ^<!-- more content --^> >>index.html
echo ^<!-- you don't need to escape ( ) outside blocks --^> >>index.html
echo ^<!-- don't escape inside quotes "&" --^> >>index.html
echo ^</html^> >>index.html

【讨论】:

以上是关于使用批处理生成 html .. 转义引号的主要内容,如果未能解决你的问题,请参考以下文章

事件处理程序

使用 TextFieldParser 处理包含未转义双引号的字段

使用 Python 的 csv.reader 处理转义引号

java怎么处理带引号的字符串

转义字符复习总结

php中怎么把json双引号前加上转义符\