我使用以下函数从我的xmlString中删除字符 \ 04 和 nulls ,但我找不到需要更改的内容避免从我的结束标记中删除\。这是我运行此功能时得到的结果
<ARR>20080625<ARR><DEP>20110606<DEP><PCIID>626783<PCIID><NOPAX>1<NOPAX><TG><TG><HASPREV>FALSE<HASPREV><HASSUCC>FALSE<HASSUCC>
有人可以帮我找出我需要在表达式中更改的内容,以便将结束标记保持为 </tag>
Private Function CleanInput(ByVal inputXML As String) As String
' Note - This will perform better if you compile the Regex and use a reference to it.
' That assumes it will still be memory-resident the next time it is invoked.
' Replace invalid characters with empty strings.
Return Regex.Replace(inputXML, "[^><\w\.@-]", "")
End Function
答案 0 :(得分:4)
Private Function CleanInput(ByVal inputXML As String) As String
Return Regex.Replace(inputXML, "[^/><\w\.@-]", "")
' --------------------------------^
End Function
但由于您的目标只是删除了\04
和\00
,因此仅限制替换它们会更安全。
Private Function CleanInput(ByVal inputXML As String) As String
Return Regex.Replace(inputXML, "[\4\0]", "")
End Function