If I have a string like "123"
, how can I split it into an array, which would look like ["", "1", "2", "3", ""]
? If I use ToCharArray()
the first Emoji is split into 2 characters and the second into 7 characters.
Update
The solution now looks like this:
public static List<string> GetCharacters(string text)
{
char[] ca = text.ToCharArray();
List<string> characters = new List<string>();
for (int i = 0; i < ca.Length; i++)
{
char c = ca[i];
if (c > 65535) continue;
if (char.IsHighSurrogate(c))
{
i++;
characters.Add(new string(new[] { c, ca[i] }));
}
else
characters.Add(new string(new[] { c }));
}
return characters;
}
Please note that, as mentioned in the comments, it doesn't work for the family emoji. It only works for emojis that have 2 characters or less. The output of the example would be: ["", "1", "2", "3", "", "", "", ""]