【问题标题】:Replace hexadecimal value in string替换字符串中的十六进制值
【发布时间】:2017-03-15 21:35:05
【问题描述】:

我收到错误'', hexadecimal value 0x03, is an invalid character. Line 440033, position 80. 另见图片:

当我尝试将 XML 文件加载到 XMLDocument 中时会发生这种情况。

我尝试以多种方式删除这个十六进制值,但都不起作用:

        Regex.Replace(responseString, "0x03", String.Empty)
        Regex.Replace(responseString, "\0x03", String.Empty)

        responseString = Regex.Replace(responseString, "0x03", String.Empty)
        responseString = Regex.Replace(responseString, "\0x03", String.Empty)

        responseString = responseString.Replace("\0x03", String.Empty)
        responseString = responseString.Replace("0x03", String.Empty)

我做错了什么?

【问题讨论】:

  • 您正在尝试替换文字字符串“0x03”,但错误消息抱怨 byte 值为 3。0x03 正是错误处理程序的方式选择显示值(这是一个不可打印的控制字符)。
  • 试试responseString = responseString.Replace(Chr(3), ""c)
  • 谢谢!但是,根据您的建议,我收到了这些错误Character constant must contain exactly one character. 和Expression expected...我也不确定您的代码中尾随c 的用途是什么?再次感谢! :)

标签: asp.net string vb.net replace hex


【解决方案1】:

我现在按照这篇文章中的建议解决了这个问题:C# Hexadecimal to char

对我来说是:

responseString = responseString.Replace(System.Convert.ToChar(System.Convert.ToUInt32("0x03", 16)), "")

【讨论】:

    猜你喜欢
    • 2018-06-12
    • 2019-08-18
    • 2019-07-27
    • 2018-01-22
    • 2018-11-12
    • 2013-08-08
    • 2011-11-12
    • 2018-03-05
    • 2011-12-07
    相关资源
    最近更新 更多