NSString:寻找上标的 Unicode:1,2,3

发布于 2024-11-26 23:51:36 字数 156 浏览 1 评论 0原文

我正在寻找 Unicode 或某种方法或字节语言,可以为 1, 2, 3 提供上标。无论出于何种原因,Unicode 都有 0, 4, 5, 6, 7, 8, 9 的上标,但没有 1, 2 , 3.

你能在 NSString 中像 HTML 那样做上标吗?

I am looking for the Unicode or some method or byte language that can put out superscripts for 1, 2, 3. For whatever reason Unicode has superscripts for 0, 4, 5, 6, 7, 8, 9, but not 1, 2, 3.

Can you do superscripts like HTML in NSString?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍风燃霜 2024-12-03 23:51:36

从字符调色板:

¹
SUPERSCRIPT ONE
Unicode: U+00B9, UTF-8: C2 B9

²
SUPERSCRIPT TWO
Unicode: U+00B2, UTF-8: C2 B2

³
SUPERSCRIPT THREE
Unicode: U+00B3, UTF-8: C2 B3

要将它们放入 NSStrings 中,您需要执行以下操作:

NSString *superscript1 = @"\u00B9";
NSString *superscript2 = @"\u00B2";
NSString *superscript3 = @"\u00B3";

From the character palette:

¹
SUPERSCRIPT ONE
Unicode: U+00B9, UTF-8: C2 B9

²
SUPERSCRIPT TWO
Unicode: U+00B2, UTF-8: C2 B2

³
SUPERSCRIPT THREE
Unicode: U+00B3, UTF-8: C2 B3

This, to make them in to NSStrings, you'd do:

NSString *superscript1 = @"\u00B9";
NSString *superscript2 = @"\u00B2";
NSString *superscript3 = @"\u00B3";
合久必婚 2024-12-03 23:51:36

我知道这个问题已经得到解答,但如果有人想重用我的代码来从标准数字字符串转换为上标,就在这里。

-(NSString *)superScriptOf:(NSString *)inputNumber{

    NSString *outp=@"";
    for (int i =0; i<[inputNumber length]; i++) {
    unichar chara=[inputNumber characterAtIndex:i] ;
    switch (chara) {
        case '1':
            NSLog(@"1");
            outp=[outp stringByAppendingFormat:@"\u00B9"];
            break;
        case '2':
            NSLog(@"2");
            outp=[outp stringByAppendingFormat:@"\u00B2"];
            break;
        case '3':
            NSLog(@"3");
            outp=[outp stringByAppendingFormat:@"\u00B3"];
            break;
        case '4':
            NSLog(@"4");
            outp=[outp stringByAppendingFormat:@"\u2074"];
            break;
        case '5':
            NSLog(@"5");
                            outp=[outp stringByAppendingFormat:@"\u2075"];
            break;
        case '6':
            NSLog(@"6");
                            outp=[outp stringByAppendingFormat:@"\u2076"];
            break;
        case '7':
            NSLog(@"7");
            outp=[outp stringByAppendingFormat:@"\u2077"];
            break;
        case '8':
            NSLog(@"8");
            outp=[outp stringByAppendingFormat:@"\u2078"];
            break;
        case '9':
            NSLog(@"9");
            outp=[outp stringByAppendingFormat:@"\u2079"];
            break;
        case '0':
            NSLog(@"0");
            outp=[outp stringByAppendingFormat:@"\u2070"];
            break;
        default:
            break;
    }
}
return outp;   
}

给定一个数字输入字符串,它只返回等效的上标字符串。

编辑(感谢jrturton):

-(NSString *)superScriptOf:(NSString *)inputNumber{

    NSString *outp=@"";
    unichar superScripts[] = {0x2070, 0x00B9, 0x00B2,0x00B3,0x2074,0x2075,0x2076,0x2077,0x2078,0x2079};

    for (int i =0; i<[inputNumber length]; i++) {

        NSInteger x =[[inputNumber substringWithRange:NSMakeRange(i, 1)]  integerValue];
        outp=[outp stringByAppendingFormat:@"%C", superScripts[x]];

    }

    return outp;   
}

I know this question has already been answered but if anyone wants to reuse my code for converting from a standard string of numbers to superscript, here it is.

-(NSString *)superScriptOf:(NSString *)inputNumber{

    NSString *outp=@"";
    for (int i =0; i<[inputNumber length]; i++) {
    unichar chara=[inputNumber characterAtIndex:i] ;
    switch (chara) {
        case '1':
            NSLog(@"1");
            outp=[outp stringByAppendingFormat:@"\u00B9"];
            break;
        case '2':
            NSLog(@"2");
            outp=[outp stringByAppendingFormat:@"\u00B2"];
            break;
        case '3':
            NSLog(@"3");
            outp=[outp stringByAppendingFormat:@"\u00B3"];
            break;
        case '4':
            NSLog(@"4");
            outp=[outp stringByAppendingFormat:@"\u2074"];
            break;
        case '5':
            NSLog(@"5");
                            outp=[outp stringByAppendingFormat:@"\u2075"];
            break;
        case '6':
            NSLog(@"6");
                            outp=[outp stringByAppendingFormat:@"\u2076"];
            break;
        case '7':
            NSLog(@"7");
            outp=[outp stringByAppendingFormat:@"\u2077"];
            break;
        case '8':
            NSLog(@"8");
            outp=[outp stringByAppendingFormat:@"\u2078"];
            break;
        case '9':
            NSLog(@"9");
            outp=[outp stringByAppendingFormat:@"\u2079"];
            break;
        case '0':
            NSLog(@"0");
            outp=[outp stringByAppendingFormat:@"\u2070"];
            break;
        default:
            break;
    }
}
return outp;   
}

Given an input string of numbers it just returns the equivalent superscript string.

Edit (thanks to jrturton):

-(NSString *)superScriptOf:(NSString *)inputNumber{

    NSString *outp=@"";
    unichar superScripts[] = {0x2070, 0x00B9, 0x00B2,0x00B3,0x2074,0x2075,0x2076,0x2077,0x2078,0x2079};

    for (int i =0; i<[inputNumber length]; i++) {

        NSInteger x =[[inputNumber substringWithRange:NSMakeRange(i, 1)]  integerValue];
        outp=[outp stringByAppendingFormat:@"%C", superScripts[x]];

    }

    return outp;   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文