Did you know that you should use TextElementEnumerator to determine the length of a string if the input might have Unicode emojis? Check out the sample below. #dotnet#csharp
I'm curious if future versions of #dotnet should do this check implicitly. 🤔
@meziantou Interestingly, the StringInfo class doesn’t have a “get length” method. There is a GetLengthOfNextElement but that just uses string.Length again.
@khalidabuhakmeh I imagine the perf degradation isn't worth it in most cases. How often does the average (if there is such a thing) app process a string with possible emoji? Better to think of String.Length as the number of wide chars. How often do you need to know the rendered length? And will the renderer even handle combining marks correctly?
Add comment