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