2017-03-22 4 views
1

私はこのようになります文字列を持っている:私がやりたい何文で入力し、スペースを取り除く

<type 'str'> 
Hi George, 

Thanks for sending me your report. 

Ill take a look at it and get back to you tomorrow. 

はこのように見ている1つの文字列にこれを変換することです:

Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow. 

どのように私はこれを行うことができますか?

+2

'str.replace( '\ n'、 '')' –

+0

strip-str.strip()を使用してください。 –

+0

@DineshPundkarは動作しません。 'strip'は開始時と終了時にのみ文字を削除します。 –

答えて

5

使用この:

>>> print(" ".join(input_str.split())) 
'Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow.' 
0
strin = # Your string 
a = strin.replace ('\n',' ') 
print (a) 

結果は:あなたは文章の間にスペースはなく、空行をしたいので
Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow.

、代替ラインはスペースで分割します。

関連する問題