【发布时间】:2011-04-28 20:30:27
【问题描述】:
首先,简要说明我这样做的原因:
我正在从 XML 加载字符串,并使用这些字符串与现有的 javascript 函数进行交互。我需要转义它们,只是因为我使用的是 webview 的 stringByEvaluatingJavaScriptFromString 方法。
我正在使用这个转义函数:
- (NSString *) stringByEscapingMetacharacters
{
const char *UTF8Input = [self UTF8String];
char *UTF8Output = [[NSMutableData dataWithLength:strlen(UTF8Input) * 4 + 1 /* Worst case */] mutableBytes];
char ch, *och = UTF8Output;
while ((ch = *UTF8Input++))
if (ch == '\'' || ch == '\'' || ch == '\\' || ch == '"')
{
*och++ = '\\';
*och++ = ch;
}
else if (isascii(ch))
och = vis(och, ch, VIS_NL | VIS_TAB | VIS_CSTYLE, *UTF8Input);
else
och+= sprintf(och, "\\%03hho", ch);
return [NSString stringWithUTF8String:UTF8Output];
}
它工作正常,除了变音符号。例如,“é”显示为“é”
那么,我怎样才能摆脱变音符号呢?
【问题讨论】:
标签: objective-c c string uiwebview diacritics