String concatenation with special character

I’m having a super strange problem when concatenating strings that contain the character. I’m iterating through words of a string and inserting a new line \n when it gets too long. If the is present in the string before the line break, it renders one invalid character and one misplaced characters. For example:

a test string: "™ 1test 2test 3test 4test 5test 6test 7test 8verylongtestword"
is changed to: "™ 1test 2test 3test 4test 5test 6test 7test\n8verylongtestword"
and rendered as:

This behavior is the same whether I use \n or \010 for the new line. And without the before the break, it renders as expected!

I’ve been trying to figure out how playdate handles these few allowed unicode characters, but I’m not having much luck. Any advice?

I suspect the string is using UTF-8 when the sign is used.

Sorry I don’t have the SDK at hand right now but can you check the length of the string with and without ™ ?

string.len("™ 1test")
string.len("A 1test")

Which method are you using to insert the linebreak?

Sure! I’m measuring pixel length instead of character count because I think my font isn’t monospaced. So get the length I’m using

both "™ 1test" and "A 1test" have a length of 51. ". 1test" has a length of 43.

To insert the linebreak I’m using

concatString = concatString … “\n”

What about character counts? That would confirm Nic’s UTF-8 theory.

ah, I see what you meant now. Yes I can confirm it’s using UTF-8

"™ 1test" length: 9
"A 1test" length: 7

Does this mean I need to do something different for line breaks?

1 Like

ok after some testing I would say this is probably a SDK bug and it has nothing to do with you concatenating some strings

You can see the bug just like that"™ Some Text \nNew line text", 0, 0)"A Some Text \nNew line text ™", 0, 80)

@SamanthaZero do you want to file a bug? otherwise I can do it, it’s up to you.

If you don’t mind, go ahead! You seem more confident and I trust you would know :slight_smile: And I appreciate your help!