python replace newline with space

Ads
 

python replace newline with space

Hi,

I want to replace newline character

\n

With space in python.

How to replace newline with space in python?

Thanks

View Answers

March 1, 2018 at 11:25 PM

Hi,

Its easy in python.

You can use the replace method of the string to performance replace operation.

Here is code example:

string = string.replace("\r","")
string = string.replace("\n","")

Thanks

Ads









Related Tutorials/Questions & Answers:
rexexp pattern to avoid certain words and replace space with underscore
rexexp pattern to avoid certain words and replace space with underscore ... to replace space between two capital words with underscore so that "River Thames... with this pattern is that it also replaces the space between "On River" to "OnRiver" and after
print the newline
print the newline  Why doesn?t the following code print the newline properly? <?php $str = ?Hello, there.\nHow are you?\nThanks for visiting.?; print $str; ?>   Hi friends, Inside the single quotes \n (newline
Advertisements
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
ereg_replace() and eregi_replace().
ereg_replace() and eregi_replace().  What is the difference between eregreplace() and eregireplace()?   Hi friends, ereg_replace() is case sensitive like "Bharat"cannot be treated as "bharat"and eregi_replace
how can i remove newline characters and tabs
how can i remove newline characters and tabs   how can i remove newline characters and tabs ? but i wont to using GUI .please help
Java write newline
Java write newline       Following example demonstrates,  how to get newline feature... of abstract writer class. In the example newLine feature is brought using
replace special characters in html
replace special characters in html  How can i replace the special characters in HTML?   Special Character in HTML HTML has a long list...; Space = &nbsp; " = &quot
Replace TEXT
Replace TEXT   I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
What is the difference between ereg_replace() and eregi_replace()?
What is the difference between ereg_replace() and eregi_replace()?  What is the difference between eregreplace() and eregireplace
replace character in php
replace character in php  PHP script that replace character
find and replace in java
find and replace in java  Need 'find and replace' function in Java to find special keyword in XMl such as @,#,!,%..and replace with their corresponding entities
MySql find and replace string
MySql find and replace string  How to find and replace string or special characters in MySql & PHP?   Find and Replace String PHP $result = preg_replace('/\band\b/i', 'foo', $subject
regexp_replace in update and replace query in postgres
regexp_replace in update and replace query in postgres  update message set data = replace (data, 'wmost','westernmost'); April 4, 2011 at 5:04 PM.... is there a way to avoid this problem. Can you send similar query using regexp_replace
Remove Extra Space At End
Remove Extra Space At End  Remove Extra Space At End
Difference between translate and replace
Difference between translate and replace   hiii, What is the difference between translate and replace?   hello, Replace replace every.... this work for entire word and pattern,. Translate replace the one charecte
Deep Learning with Python Programming
Deep Learning with Python Programming  Hi, How to learn Deep Learning with Python Programming? Thanks   Deep Learning with Python Python... Leaning, Python stands out as it provides many libraries to develop many deep
ANSI Color Codes with Python
ANSI Color Codes with Python   Use ANSI codes to play with colors and styles. Create a program that will spit out a user inputted string in a color, style, or background color that they can choose. To do this, you'll need
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
like query and then update or replace
like query and then update or replace   In postgres i use like query to find the a specific word in a column for example in a column i have text... to replace or update "wmost" to "westernmost" in that text. is there a way to do
Version of cocoon>cocoon-python dependency
List of Version of cocoon>cocoon-python dependency
Version of drools>drools-python dependency
List of Version of drools>drools-python dependency
Replace JSF Standard Error Message
Replace JSF Standard Error Message  How can we replace the JSF Standard Error Message
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space error. This error is coming while...: Java heap space where there is no more space available for the Java program... space. You can also increase the Java heap space using following parameters
Java String : Replace All
Java String : Replace All This section defines how to replace all character with specified character without using system methods. Replace All method : You can replace all specific character in a given string with another character
How to run external command in Python?
How to run external command in Python?  Hi, I am writing an application in Python and there is requirement of calling the external command from the Python program. I spend some time but could not find good example of calling
Program to Ignore Space and Enter ?!
Program to Ignore Space and Enter ?!  Hi, dear friend i wont to write program to enter many statements, if i use Space and Enter in the Run Time must be delete the space and ignore the Enter ..for example if i entered
java.lang.OutOfMemoryError: Java heap space
" java.lang.OutOfMemoryError: Java heap space How to resolve this issue? Thanks   Hi... your program. Check the thread Java heap space and java.lang.OutOfMemoryError: Java heap space. Thanks
MySQL Replace
MySQL Replace       MySQL Replace function finds and replaces the occurrences of specified string...: REPLACE( String_Text, String_FROM, String_TO); where String_Text
xmlname space in java
xmlname space in java  hi i want to write code like , i used setAttribute method for this. but its showing ERROR: 'Namespace for prefix 'company' has not been declared.' javax.xml.transform.TransformerException

Ads