如何删除vb.net中的新行?

时间:2013-08-09 10:53:13

标签: vb.net

我在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

1 个答案:

答案 0 :(得分:1)

您可以在字符串上使用replace方法。

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

使用Environment.NewLine可以确保无论代码在哪里,它仍然可以在新行上可靠地拆分,例如,如果它是为在Linux上运行的单声道编译的,那么新行只是一个回车。

当然,对于您的示例,您只需删除添加新行的行:

ResponseMessage += vbCrLf 'remove these lines from your code and the new lines will disappear