how to print characterSet in objective c?

元气小坏坏 提交于 2019-12-01 16:59:53

This will do the first 65536 characters in unicode, which will do for most situations. I believe unicode can go much higher (2^32?), but this would take much longer to log.

+ (void) logCharacterSet:(NSCharacterSet*)characterSet
{
    unichar unicharBuffer[20];
    int index = 0;

    for (unichar uc = 0; uc < (0xFFFF); uc ++)
    {
        if ([characterSet characterIsMember:uc])
        {
            unicharBuffer[index] = uc;

            index ++;

            if (index == 20)
            {
                NSString * characters = [NSString stringWithCharacters:unicharBuffer length:index];
                NSLog(@"%@", characters);

                index = 0;
            }
        }
    }

    if (index != 0)
    {
        NSString * characters = [NSString stringWithCharacters:unicharBuffer length:index];
        NSLog(@"%@", characters);
    }
}

There are some quite fun looking results, for example here is a sample of 20 characters from punctuationCharacterSet.

༅༆༇༈༉༊་༌།༎༏༐༑༒༔༺༻༼༽྅

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!