V
V
Vampre2020-06-10 06:55:18
Python
Vampre, 2020-06-10 06:55:18

How to find all line breaks in a text?

How can you solve the problem of such a plan: Find all line breaks (paragraphs, lists, etc.) in the text and replace them with the character "\n" without quotes.

I don’t ask you to write a ready-made function, tell me the algorithm of actions or what modules can I use here?
It is clear that you need to look for characters in the text and change them to \n, but I don’t understand in what form they can be.
For example the list character • would be unicode '\U2022' or '•'...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-06-10
@Vampre

You can use regular expressions, or you can use the replace() function:

stroka = '''
• Строка1
• Строка2
• строка3
'''
r = stroka.replace('•', '\\n')
print(r)
>>>
\n Строка1
\n Строка2
\n строка3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question