Last active
May 30, 2019 17:21
-
-
Save regakakobigman/00e75029dd0d7b505683143e598b5742 to your computer and use it in GitHub Desktop.
Line splitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# originally by GogetaX (Discord: @274253761399095297) | |
func LineSpliter(txt,MaxTextLength): | |
var Finish = false | |
var a = -1 | |
var Lines = [] | |
var t = "" | |
var LastBreak = -1 | |
while !Finish: | |
a += 1 | |
if txt[a] == " " || txt[a] == "." || txt[a] == "?" || txt[a] == "!": | |
LastBreak = a | |
t = t + txt[a] | |
if t.length() >= MaxTextLength: | |
if LastBreak >=MaxTextLength / 2: | |
t = t.left(LastBreak+1) | |
Lines.append(t) | |
else: | |
Lines.append(t) | |
txt = txt.right(t.length()) | |
a = -1 | |
t = "" | |
LastBreak -1 | |
if a+2>txt.length(): | |
Finish = true | |
break | |
Lines.append(t) | |
#Trip Ends | |
for x in range(Lines.size()): | |
if Lines[x].ends_with(" "): | |
Lines[x] = Lines[x].left(Lines[x].length()-1) | |
return Lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment