【问题标题】:Conversion from string "<IVCreateItemPriceListType><eCon" to type 'Double' is not valid从字符串“<IVCreateItemPriceListType><eCon”到类型“Double”的转换无效
【发布时间】:2013-12-31 06:29:09
【问题描述】:

我正在尝试将字符串值复制到字符串,但出现错误:

从字符串“转换”

可能是空间导致错误。让我知道如何使用 VB.Net 删除这些行。

代码:

  Sub Main()

    Dim x As String = "<IVCreateItemPriceListType><eConnectProcessInfo xsi:nil=" + True + " /><taRequesterTrxDisabler_Items xsi:nil=" + True + " /><taIVCreateItemPriceListLine_Items><taIVCreateItemPriceListLine><ITEMNMBR>SAMSUNG</ITEMNMBR><CURNCYID>Z-US$</CURNCYID><PRCLEVEL>SUPPORT</PRCLEVEL><UOFM>Each</UOFM><UOMPRICE>80</UOMPRICE></taIVCreateItemPriceListLine><taIVCreateItemPriceListLine xsi:nil=" + True + " /></taIVCreateItemPriceListLine_Items><taIVCreateItemPriceListHeader><ITEMNMBR>SAMSUNG</ITEMNMBR><UOFM>Each</UOFM><PRCLEVEL>SUPPORT</PRCLEVEL><CURNCYID>Z-US$</CURNCYID></taIVCreateItemPriceListHeader></IVCreateItemPriceListType></eConnect>"



    x = x.Replace("<eConnectProcessInfo xsi:nil=" + True + " />", "")
    x = x.Replace("<taRequesterTrxDisabler_Items xsi:nil=" + True + " />", "")
    x = x.Replace("<taIVCreateItemPriceListLine xsi:nil=" + True + " />", "")

End Sub

【问题讨论】:

    标签: vb.net type-conversion


    【解决方案1】:

    在您的字符串和替换语句中,您使用了

    + True +
    

    如果没有用双引号 "" 括起来,这意味着您正在尝试添加一个带有 bool 值的字符串并导致异常。要解决此问题,请将 + True + 替换为

    + "True" +
    

    更新您的代码在编辑后将如下所示:

    Sub Main()
    
        Dim x As String = "<IVCreateItemPriceListType><eConnectProcessInfo xsi:nil=" + True + " /><taRequesterTrxDisabler_Items xsi:nil=" + "True" + " /><taIVCreateItemPriceListLine_Items><taIVCreateItemPriceListLine><ITEMNMBR>SAMSUNG</ITEMNMBR><CURNCYID>Z-US$</CURNCYID><PRCLEVEL>SUPPORT</PRCLEVEL><UOFM>Each</UOFM><UOMPRICE>80</UOMPRICE></taIVCreateItemPriceListLine><taIVCreateItemPriceListLine xsi:nil=" + "True" + " /></taIVCreateItemPriceListLine_Items><taIVCreateItemPriceListHeader><ITEMNMBR>SAMSUNG</ITEMNMBR><UOFM>Each</UOFM><PRCLEVEL>SUPPORT</PRCLEVEL><CURNCYID>Z-US$</CURNCYID></taIVCreateItemPriceListHeader></IVCreateItemPriceListType></eConnect>"
    
    
    
        x = x.Replace("<eConnectProcessInfo xsi:nil=" + "True" + " />", "")
        x = x.Replace("<taRequesterTrxDisabler_Items xsi:nil=" + "True" + " />", "")
        x = x.Replace("<taIVCreateItemPriceListLine xsi:nil=" + "True" + " />", "")
    
    End Sub
    

    您可以使用 Visual Studio 中的Find and Replace 功能找到+ True + 并替换为+ "True" +

    【讨论】:

    • 感谢您的回复...让我知道如何在不使用替换的情况下删除这些行。
    • @Havab remove that lines without using replace 是什么意思?你的意思是不想在 Visual Studio 中使用find and replace 功能?
    • 实际上我必须使用 Remove 方法从使用 replace 方法插入的字符串中删除行。 ...
    • 我认为用“”替换行是在您的情况下删除它的最佳方法
    • 我怎样才能用双码显示真值,如 = ex : Dim value As String = "" 输出如下: 所需输出:
    猜你喜欢
    • 2011-07-30
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多