I would like to put a string into a byte array, but the string may be too big to fit. In the case where it’s too large, I would like to put as much of the string as possible into the array. Is there an efficient way to find out how many characters will fit?
Share
In order to truncate a string to a UTF8 byte array without splitting in the middle of a character I use this:
The returned string can then be safely transferred to a byte array of length maxLength.