how to print characterSet in objective c?

后端 未结 1 1371
攒了一身酷
攒了一身酷 2021-01-18 00:13

i\'m using GNUstep shell for programming objective-c. I\'m able to convert string to a character set. But unable to print the converted character set in the console. Please

相关标签:
1条回答
  • 2021-01-18 00:30

    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.

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

    0 讨论(0)
提交回复
热议问题