如何從NSString中提取前3個字符?如何從NSString中提取前3個字符?
例如,如果我有一個字符串「1234820」我如何從字符串中提取數字123並將結果存儲爲格式爲「1.23百萬」的新字符串?
我指望的字符串中的字符數用
-(NSString *)returnFormattedString:(NSString *)stringToFormat{
NSString *formatedString;
NSUInteger characterCount = [stringToFormat length];
if (characterCount > 6) {
//???? How do I extract and add a decimal
stringWithThreeCharactersAndDecimal = ????;
NSString *string = [NSString stringWithString:stringWithThreeCharactersAndDecimal];
formatedString = [string stringByAppendingString:@"Million"];
}
return formatedString;
}
難道你不想要像[這樣](http://stackoverflow.com/questions/11993806/convert-int-to-shortened-formatted-string)這是更通用的,因爲它不假設有7 -digits? – Droppy