1

In the unity android I have to restrict the specific name to maximum length of 25.Emojis are also allowed to be used.I want to know how we can restrict the emojis so that the name is < 25.For the characters it works fine.

if(name>Max_Length)
{
  myName=name.SubString(0,Max_Length);
}

How can i restrict the emojis because emoji's take 2-4 bytes.With this if emoji's 1 byte has been taken when the name reaches 25 characters it invalidates that emoji(I get a box).If this is the case I don't want to take the last emoji.Please help.Currently I am using TouchScreenKeyboard class in unity.

  • How is emoji's bytes calculated? by string length? – Programmer Jun 06 '16 at 07:25
  • The name can contain alphabets and emojis.So together they are considered as single string.It works fine only for alphabets.But with the emojis if the emoji does not within preferred maximum length it invalidates the last emoji. – Architha Shastry Jun 06 '16 at 08:48
  • To process string with emojis : string input = .... for(int i = 0 ; i < input.Length ; i += Char.IsSurrogatePair(input,i) ? 2 : 1) { int x = Char.ConvertToUtf32(input, i); Console.WriteLine("U+{0:X4}", x); } To render emoji string in unity : or emoji assist: https://www.assetstore.unity3d.com/en/#!/content/53240 – Chris Sep 28 '16 at 20:38

1 Answers1

1

This can be done with the LengthInTextElements function in the stringInfo class which considers the emoji as a single character. https://msdn.microsoft.com/enus/library/system.globalization.stringinfo.lengthintextelements(v=vs.110).aspx