Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove carriage return from string

I would like to insert the following into a string

<p>some text here</p> <p>some text here</p> <p>some text here</p> 

I want it to go into a string as follows

<p>some text here</p><p>some text here</p><p>some text here</p> 

i.e. without the carriage returns.

How do I achieve this?

like image 823
oshirowanen Avatar asked Feb 05 '11 10:02

oshirowanen


People also ask

How do I remove a carriage return from a string in Java?

replaceAll("\\n", ""); s = s. replaceAll("\\r", ""); But this will remove all newlines. Note the double \ 's: so that the string that is passed to the regular expression parser is \n .

Does string trim remove carriage return?

It handles all line terminator characters (LF, CR, etc). The method also removes any leading or trailing spaces or tabs. The trim() method doesn't change the original string, it returns a new string. Strings are immutable in JavaScript.

How do I remove a carriage return from a string in Python?

Use the strip() Function to Remove a Newline Character From the String in Python. The strip() function is used to remove both trailing and leading newlines from the string that it is being operated on. It also removes the whitespaces on both sides of the string.


1 Answers

Since you're using VB.NET, you'll need the following code:

Dim newString As String = origString.Replace(vbCr, "").Replace(vbLf, "") 

You could use escape characters (\r and \n) in C#, but these won't work in VB.NET. You have to use the equivalent constants (vbCr and vbLf) instead.

like image 156
Cody Gray Avatar answered Sep 23 '22 20:09

Cody Gray