我正在尋找Unicode或某種方法或字節語言,可以爲1,2和3輸出上標。無論出於何種原因,Unicode上標記爲0,4 ,5,6,7,8,9,但不是1,2,3,NSString:尋找Unicode上標:1,2,3
你可以在NSString
做HTML的上標嗎?
我正在尋找Unicode或某種方法或字節語言,可以爲1,2和3輸出上標。無論出於何種原因,Unicode上標記爲0,4 ,5,6,7,8,9,但不是1,2,3,NSString:尋找Unicode上標:1,2,3
你可以在NSString
做HTML的上標嗎?
從字符欄:
¹
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";
我知道這個問題已經回答了,但如果有人想重用我的代碼從號碼上標一個標準字符串轉換,在這兒呢。
-(NSString *)superScriptOf:(NSString *)inputNumber{
NSString *[email protected]"";
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 *[email protected]"";
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;
}
鉑就會簡單得多擁有所有的字符數組,然後只取objectAtIndex從陣列。 – jrturton
感謝信息...這裏是在雅 –