Carriage conversion

I am importing an xml message file in Django.

Part of this process requires me to convert escaped html characters to their html form using replace:

s = s.replace("&lt;", "<")

My problem is that the xml file when viewed with vim contains a carriage return in the form "^ M". I would like to convert these carriage returns to break tags, but

s = s.replace("^M", "<br />")

doing nothing.

I tried to convert all these tags to an xml file using vim, but then my midim importer breaks.

Any idea on how I can perform this conversion using replace?

+3
source share
1 answer

Using one or both of these should work:

s = s.replace("\r\n", "<br />")
s = s.replace("\n", "<br />")
+8
source

All Articles