本文共 1138 字,大约阅读时间需要 3 分钟。
Objective-C??????????
????????Objective-C?????????????????????????????????
?????
#importNSString *replaceCharacters(NSString *input, NSDictionary *replacementMap) { // ???????????? NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:input]; // ??????????? for (NSUInteger index = 0; index < [str length]; index++) { // ?????? NSString *charToReplace = [str substringWithRange:NSMakeRange(index, 1)]; // ????????? NSString *replacement = [replacementMap objectForKey:charToReplace]; // ??????????? if (replacement) { // ???? [str replaceCharactersInRange:NSMakeRange(index, 1) withString:replacement]; } } return [str string];}
?????
????????Foundation?????????NSString?NSAttributedString???
??replaceCharacters???????input?????????????replacementMap????????????????????????
???????NSMutableAttributedString??????????????????
????????????????????????????????????????
????????????????replaceCharactersInRange????????
????????????????
???????????????????????????????????????????????????????????
转载地址:http://jusfk.baihongyu.com/