0
u'The disclosure relates to systems and methods for detecting features on\n     billets     of laminated veneer lumber (LVL). In some embodiments, an LVL\n     billet is provided and passed through a scanning assembly. The scanning\n     assembly includes anx-raygenerator and anx-raydetector. Thex-raygenerator generates a beam ofx-rayradiation and thex-raydetector\n     measures intensity of the beam ofx-rayradiation after is passes through\n     the LVL billet. The measured intensity is then processed to create an\n     image. Images taken according to the disclosure may then be analyzed todetectfeatures on the LVL billet.'

以上是我的输出。现在我想摆脱 Python 中的“\n”。

我怎么能意识到这一点?我应该使用 re 模块吗?我text用来代表上面所有的文字,text.strip("\n")完全没有用。为什么?

谢谢你!

4

4 回答 4

6

对于一个字符串, s, 做:

s = s.strip("\n")

只会删除前导和尾随换行符。

你想要的是

s = s.replace("\n", "")
于 2013-03-29T09:42:53.223 回答
1

你试过替换功能吗?

s = u'The disclosure relates to systems and methods for detecting features on\n     billets     of laminated veneer lumber (LVL). In some embodiments, an LVL\n     billet is provided and passed through a scanning assembly. The scanning\n     assembly includes anx-raygenerator and anx-raydetector. Thex-raygenerator generates a beam ofx-rayradiation and thex-raydetector\n     measures intensity of the beam ofx-rayradiation after is passes through\n     the LVL billet. The measured intensity is then processed to create an\n     image. Images taken according to the disclosure may then be analyzed todetectfeatures on the LVL billet.'

s.replace('\n', '')
于 2013-03-29T09:45:32.720 回答
0

试试这个

''.join(a.split('\n'))

a 是输出字符串

于 2013-03-29T09:43:15.940 回答
-1
str = 'The disclosure relates to systems and methods for detecting features on\n     billets     of laminated veneer lumber (LVL).'
str.replace('\n', '')
' '.join(str.split())

输出

The disclosure relates to systems and methods for detecting features on billets of laminated veneer lumber (LVL).
于 2013-03-29T09:45:56.780 回答