我有一个字符串:
NSString *str1 = @"\u2022 You were held in custody for a longer
period of time than may have been necessary.";
我正在使用以下代码将其转换为HTML字符串:
- (NSString *)HTMLString {
NSDictionary * const exportParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:str1];
NSData *htmlData = [attributed dataFromRange:NSMakeRange(0, attributed.length) documentAttributes:exportParams error:nil];
return [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
}
但是HTML字符串中没有显示项目符号。它显示?
而非子弹点。请告诉我任何解决方案。
答案 0 :(得分:1)
请尝试以下代码 -
- (NSString *)HTMLString {
NSDictionary * const exportParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
letterString = [letterString stringByReplacingOccurrencesOfString:@"\u2022" withString:@"•"];
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:letterString];
NSData *htmlData = [attributed dataFromRange:NSMakeRange(0, attributed.length) documentAttributes:exportParams error:nil];
return [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
}