I have this code that works in PS 7.1 to count the overall length of a string that includes emojis.
In 5.1 it doesn't return the correct values. So to prevent you from wasting your time it would be best to use 7.1.
My question is:
How do I get the emoji count using PowerShell 7.1?
Add-Type -AssemblyName System.Globalization
$str = '️' # 7.1 Returns 3 but 5.1 returns 13.
#$str = '' # 7.1 Returns 7 but 5.1 returns 7.
#$str = "'What is this?' " # 7.1 Returns 22 but 5.1 returns 30.
$se = [System.Globalization.StringInfo]::GetTextElementEnumerator($str)
$cnt = 0
while($se.MoveNext()) { $cnt += 1 }
$cnt
My required output should be (emoji count only):
'️' # Should return 3.
'' # Should return 7.
"'What is this?' " # Should return 4.
There are 3,512 emojis at the time of writing.
☺️️☹️☠️❣️❤️❤️❤️️️️️️️✋✋✋✋✋✋✌️✌✌✌✌✌☝️☝☝☝☝☝✊✊✊✊✊✊✍️✍✍✍✍✍️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚕️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️⚖️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️️️♂️♂️♂️♂️♂️♂️️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♀️♂️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️️♂️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️⛷️️️♂️♂️♂️♂️♂️♂️️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️⛹️⛹⛹⛹⛹⛹⛹️♂️⛹♂️⛹♂️⛹♂️⛹♂️⛹♂️⛹️♀️⛹♀️⛹♀️⛹♀️⛹♀️⛹♀️️️♂️♂️♂️♂️♂️♂️️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️♂️♂️♂️♂️♂️♂️♀️♀️♀️♀️♀️♀️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️️⬛️❄️️️️️☘️️☕️️️⛰️️️️️️️️️️️⛪⛩️⛲⛺️♨️️️️️️⛽⚓⛵️⛴️️✈️️️️⌛⏳⌚⏰⏱️⏲️️️☀️⭐☁️⛅⛈️️️️️️️️️️☂️☔⛱️⚡❄️☃️⛄☄️✨️️️⚽⚾⛳⛸️️♠️♥️♦️♣️♟️️️️⛑️️️️☎️️️⌨️️️️️️️️✉️️✏️✒️️️️️️️️️✂️️️️️⛏️⚒️️️⚔️️⚙️️⚖️⛓️⚗️️️⚰️⚱️♿⚠️⛔☢️☣️⬆️↗️➡️↘️⬇️↙️⬅️↖️↕️↔️↩️↪️⤴️⤵️⚛️️✡️☸️☯️✝️☦️☪️☮️♈♉♊♋♌♍♎♏♐♑♒♓⛎▶️⏩⏭️⏯️◀️⏪⏮️⏫⏬⏸️⏹️⏺️⏏️♀️♂️⚧️✖️➕➖➗♾️‼️⁉️❓❔❕❗〰️⚕️♻️⚜️⭕✅☑️✔️❌❎➰➿〽️✳️✴️❇️©️®️™️#️⃣*️⃣0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣️️ℹ️Ⓜ️️️️️㊗️㊙️⚫⚪⬛⬜◼️◻️◾◽▪️▫️️️️⚧️☠️
Some useful links: