- Joined
- Jun 30, 2008
- Messages
- 3,451
- Reaction score
- 1,616
PHP:
private static readonly char[] SEARCH_TAG_CHARS = "0289PYLQGRJCUV".ToCharArray();
public static string GetHashtagFromId(long id)
{
if (GetHighInt(id) <= 255)
{
StringBuilder sb = new StringBuilder();
int cnt = 11;
int ccnt = Constants.SEARCH_TAG_CHARS.Length;
id = ((long)GetLowInt(id) << 8) + (GetHighInt(id));
do
{
sb.Append(Constants.SEARCH_TAG_CHARS[(int)(id % ccnt)]);
id /= ccnt;
if (id <= 0)
{
break;
}
} while (++cnt > 0);
sb.Append("#");
return new string(sb.ToString().Reverse().ToArray());
}
return "";
}
public static int GetLowInt(long l)
{
return (int)(l & 0xFFFFFFFF);
}
public static int GetHighInt(long l)
{
return (int)(l >> 32);
}
This is how Clash of Clans creates their hashtags. Enjoy.
Last edited: