将\ n替换为< br/> [英] Replace \n with <br />
本文介绍了将\ n替换为< br/>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python解析文件中的文本.我必须将所有换行符(\ n)替换为
,因为此文本将生成html-content.例如,这是文件中的几行:
I'm parsing text from file with Python. I have to replace all newlines (\n) with
cause this text will build html-content. For example, here is some line from file:
'title\n'
现在我要做:
thatLine.replace('\n', '<br />')
print thatLine
我仍然看到带有换行符的文本.
And I still see the text with newline after it.
推荐答案
只是踢腿,您也可以这样做
Just for kicks, you could also do
mytext = "<br />".join(mytext.split("\n"))
用<br />
替换字符串中的所有换行符.
to replace all newlines in a string with <br />
.
这篇关于将\ n替换为< br/>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文