Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Using replace() method to remove newlines from a string

# Python code to remove newline character from string using replace() method

text = "A regular 
 expression is a sequence 
 of characters
 that specifies a search
 pattern. "
print(text.replace('
', ''))

my_list = ["Python
", "is
", "Fun
"]
new_list = []

print("Original List: ", my_list)

for i in my_list:
    new_list.append(i.replace("
", ""))
print("After removal of new line ", new_list)
Source by itsmycode.com #
 
PREVIOUS NEXT
Tagged: #Using #method #remove #newlines #string
ADD COMMENT
Topic
Name
6+9 =