So there is a string of values separated by n.
for example:
"link1nlink2nlink3nlink4n"
I’m trying to send a message in telegram API but it has a length limit of 4050 characters. How can split the string into chunks of 4050 chars or less at n characters so it doesn’t mess up any links?
so I want the end result to be a list of strings containing 4050 characters or less, and the original list splitting points should be at "n" character.
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
2
Answers
You can use
.split()
and list comprehension:Output:
You can use
textwrap.wrap
:example:
Alternative to break on
n
exactly: