Split String into chunks by length and bytes

I have a VB.NET WebAPI that needs to send SMS messages that are limited to either 160 characters or 140 bytes, whichever comes first. I say bytes as well because the SMS standard is bizarre and certain characters like square brackets take up more bytes than others.

My users often want to type long paragraphs of text and instead of imposing a limit on them I’d rather just break the message into multiple parts for them.

The problem I have is that I am not comfortable breaking words or URLs apart. I want to break a long message into proper, predictable, and readable “chunks”. Breaking a string into parts by character count is easy but adding in the byte size issue and not word-breaking or URL-breaking adds in a lot of complexity that I’m not sure how to wrap my head around in code.

submitted by /u/Apk07
[link] [comments]

Leave a Reply