当前位置: 动力学知识库 > 问答 > 编程问答 >

stray characters in html page created in iphone by replacing tags

问题描述:

i have an html page saved in my bundle,i have certain tags in the html like {PRICE} etc and these are replaced by actual values in the runtime by the code

str=[str stringByReplacingOccurrencesOfString:@"{PRICE}" withString:[self currencyForKey:@"my price"]];

i have ensured that no null values are returned by this currencyforkey method,but after the whole html page is created by replacing all tags with such values,and displaying in webview some special stray characters are included in the final web page. these special characters are

i checked the whole initial html page and my entire project for such characters but not found then from where might be such things coming ??? i am using nsasciistring encoding to create the string from html saved in the bundle

NSString *path=[[NSBundle mainBundle] pathForResource:@"myhtml" ofType:@"html"];

NSData *htmlData=[NSData dataWithContentsOfFile:path];

NSString *tableStr=[[NSString alloc] initWithData:htmlData encoding:(NSStringEncoding)NSASCIIStringEncoding];

网友答案:

Are you sure that the HTML page in your bundle is in ASCII encoding? If it were e.g. in UTF-8 encoding, then using NSASCIIStringEncoding may well cause unexpected stray characters to be displayed.

分享给朋友:
您可能感兴趣的文章:
随机阅读: