Few days ago we've talked about method EnumerateRunes.

EnumerateRunes that we've learned is helpful but might not be enough. Trying to count characters in the following "\uD83D\uDC68\u200D\uD83D\uDE80" (👨‍🚀 = Man + ZWJ + Rocket) with chars or Runes might give us wrong results (5 vs 3). How can we get the correct number of elements?

StringInfo can help us with that. It has elements like ParseCombiningCharacters that allows to get the correct number. On the other hand, GetTextElementEnumerator allows getting an enumerator that allows traversing the elements of a string.

Docs 📑: https://learn.microsoft.com/en-us/dotnet/api/system.globalization.stringinfo?view=net-8.0

#dotnet #api #stringinfo #uncode
---
If you find this useful, consider giving a like & share ♻

StringInfo Class (System.Globalization)

Provides functionality to split a string into text elements and to iterate through those text elements.