I have returned from one function as plain multi-line text, which I should print in Telegram or Discord. The problem is the character limit for one message. And text should only be separated by line. E.g.
limit = 50
text = "Line1 - some text
Line2 - some text
Line3 - some text, limit here
Line4 - some text"
I need to do smth to get
text1 = "Line1 - some text
Line2 - some text"
text2 = "Line3 - some text, limit here
Line4 - some text"
or any other way to separate long string onto several parts, but only by lines.
This is the wrong result:
text1 = "Line1 - some text
Line2 - some text
Line3 - some"
text2 = "text, limit here
Line4 - some text"
2
Answers
A simple solution would be something like
I suspect theres a better way to do this in just a few lines with some clever splitting or regex, but this is a brute way to split it up into smaller messages by line. Note that this will attempt to send lines that are over the character limit, and it can definitely be improved.
simple example to split data to buffer
results