0

我在删除 vb .net 中的新行时遇到问题:

Title = Honus Wagner: The Life of Baseball's "Flying Dutchman"

Author = Arthur D. Hittner,  
ListPrice = $35.00

TotalOffers = 0

在标题和作者之间,然后是 ListPrice 和 TotalOffers 我不想要新的(免费)行。如何使用 vb.net 删除这个新行?

参考这段代码:

MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ItemAttributes/amz:Title", MyXmlNamespaceManager)                                              
ResponseMessage += "Title = " & MyXmlNode.InnerText  
ResponseMessage += vbCrLf

MyXmlNodeList = ItemXmlNode.SelectNodes("amz:ItemAttributes/amz:Author", MyXmlNamespaceManager)  
   If IsNothing(MyXmlNodeList) = False Then  
            ResponseMessage += "Author = "  
               For Each MyXmlNode In MyXmlNodeList  
           ResponseMessage += MyXmlNode.InnerText & ", "  
               Next  
   End If  
ResponseMessage += vbCrLf

MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ItemAttributes/amz:ListPrice/amz:FormattedPrice", MyXmlNamespaceManager)  
             ResponseMessage += "ListPrice = "  
                  If IsNothing(MyXmlNode) = False Then  
                       ResponseMessage += MyXmlNode.InnerText  
                  End If  
ResponseMessage += vbCrLf  

MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Offers/amz:TotalOffers", MyXmlNamespaceManager)
     ResponseMessage += "TotalOffers = " & MyXmlNode.InnerText
4

1 回答 1

1

您可以只对字符串使用 replace 方法。

myStringFromMyXmlNode = myStringFromMyXmlNode.Replace(Environment.NewLine, "")

使用Environment.NewLine确保无论您的代码走到哪里,它仍然会在新行上可靠地拆分,例如,如果它是为在 Linux 上运行的 mono 编译的,而新行只是一个回车符。

当然,对于您的示例,您可以简单地删除添加新行的行:

ResponseMessage += vbCrLf 'remove these lines from your code and the new lines will disappear
于 2013-08-09T10:57:09.093 回答