问题描述
我正在使用GNUstep外壳对Objective-C进行编程.我能够将字符串转换为字符集.但是无法在控制台中打印转换后的字符集.请告诉我一种打印方法.预先感谢.
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 tell me a way to print it. Thanks in advance.
推荐答案
这将处理unicode中的前65536个字符,这在大多数情况下都适用.我相信unicode可以更高(2 ^ 32吗?),但这将花费更长的时间记录.
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);
}
}
有一些非常有趣的结果,例如,下面是punctuationCharacterSet
中20个字符的示例.
There are some quite fun looking results, for example here is a sample of 20 characters from punctuationCharacterSet
.
这篇关于如何在目标c中打印characterSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!