【发布时间】:2018-07-23 09:26:05
【问题描述】:
我正在使用 VBScript 并且有一个将 xml 转换为文本文件的脚本。
我正在尝试将字符串 ###EntryEnd###\| 替换为 LF 字符。
我在替换模式中尝试了\n 和\x0a,但它们不起作用。我发现的唯一解决方法是改用Chr(10)。
我一直在寻找此行为的答案,但无法找到它。 \n 和 \x0a 都应该可以工作。有什么建议吗?
代码如下:
' Method to process the file
Private Function PrepFile(ByVal strInp)
With New RegExp
.Global = True
.Pattern = "\|"
strInp = .Replace(strInp, "")
.Pattern = "<xmldoc .*?xml:lang=""([^""]+)"">"
strInp = .Replace(strInp, "English|$1|Part Of Speech|Note|EngDef|Glossary Definition###EntryEnd###|")
.Pattern = "<remove>.*?</remove>"
strInp = .Replace(strInp, "")
.Pattern = "(<tab/>|</para>)"
strInp = .Replace(strInp, "|")
.Pattern = "<[^>]*>"
strInp = .Replace(strInp, "")
.Pattern = "\n"
strInp = .Replace(strInp, "")
.Pattern = "###EntryEnd###\|"
strInp = .Replace(strInp, chr(10))
End With
PrepFile = strInp
End Function
示例文件sn-p:
<?xml version="1.0" encoding="UTF-8"?>
<xmldoc source="" type="TERMS" xml:lang="hu-HU">
<para id="13" name="Entry"><notrans><seg>School Administrator</seg><tab/></notrans><remove>___________</remove><seg>iskolavezető</seg></para>
<para id="14" name="Usage"><notrans><seg> </seg><tab/></notrans><remove>HASZNÁLAT:</remove><seg> </seg></para>
<para id="15" name="EntryText"><notrans><seg> </seg><tab/></notrans><remove>MEGHATÁROZÁS:</remove><seg> </seg></para>
<para id="16" name="Context"><remove>PÉLDA:</remove><remove><seg>Cathy Brown iskolavezető</seg></remove><notrans>###EntryEnd###</notrans></para>
<para id="17" name="Entry"><notrans><seg>School Resource Officer</seg><tab/></notrans><remove>___________</remove><seg>iskolarendőr</seg></para>
<para id="18" name="Usage"><notrans><seg> </seg><tab/></notrans><remove>HASZNÁLAT:</remove><seg> </seg></para>
<para id="19" name="EntryText"><notrans><seg>a law enforcement officer who is responsible for providing security and crime prevention services in schools in parts of the United States and Canada.|</seg><tab/></notrans><remove>MEGHATÁROZÁS:</remove><seg>rendőr, aki azért felelős, hogy az iskolákban biztonsági és bűnmegelőzési feladatokat lásson az Egyesült Államok és Kanada egyes területein.</seg></para>
<para id="20" name="Context"><remove>PÉLDA:</remove><remove><seg>Ocalai iskolarendőrök</seg></remove><notrans>###EntryEnd###</notrans></para>
</xmldoc>
【问题讨论】:
标签: regex replace vbscript substitution metacharacters