NOTE: this only looks good on monospace text. source code pro is monospace since all the characters are the same width. sans-serif is not because, for example, the “i” is not the same width as the “w”. the number of characters will be wrapped well, but it doesn’t account for different widths.
this is a function that makes line breaks in a string based on a width. it also chops words up when it’s longer than the width, adding dashes to the end.
some cool stuff it does
cuts words off when needed
safeguard thingy
a width of less than 2 would crash the code. but there’s a safety here so that you don’t make a mistake. sorta. it doesn’t stop the program, it returns a different string instead. i should probably make it raise an error.
of course, it’s not that good code-wise. there is repeated code in there that caused a few mistakes that i eventually fixed. but i’m still quite proud of it, and i hope it comes in handy.
no, this is not copied off the internet. i did make this with my head.
credit is optional if you want to use or edit it, but it would be appreciated.
text wrap5-7-2021_10-36-58.wick (46.2 KB)