Pages

2022-11-24

Go for C# developers: Unicode strings

 There are a few gotchas with strings in Go if they contain unicode characters.

For example, if you loop over a string using range to get all characters, you will actually only loop over the starting index for each character. Similarly the built in len function will return the number of bytes used in the string and not the number of visible characters.

Here is an example showing how the index variable is "jumping" to each character in the string and how accessing each character in the string using that index is not working as expected.

No comments:

Post a Comment