softwaresolution
softwaresolution

Reputation: 21

How to remove the new line in vb.net?

I have a problem to remove new line in vb .net:

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

Author = Arthur D. Hittner,  
ListPrice = $35.00

TotalOffers = 0

Between the title and author, then ListPrice and TotalOffers I don't want that new(free) line. How to remove this new line using vb.net?

refer this code:

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

Upvotes: 0

Views: 1033

Answers (1)

Sean Airey
Sean Airey

Reputation: 6372

You can just use the replace method on a string.

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

Using Environment.NewLine makes sure that wherever your code goes, it will still reliably split on the new line, for example if it's compiled for mono which runs on Linux where the new line is just a carriage return.

Of course, for your example you could simply remove the lines where you add a new line:

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

Upvotes: 1

Related Questions