当我搜索某个位置时,有时会从placemark.subThoroughfare
获取此字符串
如何将该符号重新格式化为正常的“ - ”?
非常感谢答案
答案 0 :(得分:0)
假设问题是En Dash或Em Dash字符,这里是一个示例解析。如果你的角色不同,请查看UTF8数据,然后使用它。
NSString *enDashCharacter = [NSString stringWithUTF8String:"\xe2\x80\x93"];
NSString *emDashCharacter = [NSString stringWithUTF8String:"\xe2\x80\x94"];
NSLog(@"enDashCharacter: %@", enDashCharacter);
NSLog(@"emDashCharacter: %@", emDashCharacter);
NSString *textString = [NSString stringWithFormat:@"1-2 3%@4 5%@6", enDashCharacter,emDashCharacter];
NSData *textData = [textString dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"textString: '%@'", textString);
NSLog(@"textData: %@", textData);
NSString *newString = textString;
newString = [newString stringByReplacingOccurrencesOfString:enDashCharacter withString:@"-"];
newString = [newString stringByReplacingOccurrencesOfString:emDashCharacter withString:@"-"];
NSLog(@"newString: '%@'", newString);
NSData *newStringData = [newString dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"newStringData: %@", newStringData);
NSLog输出:
enDashCharacter: -
emDashCharacter: -
textString:'1 - 2 3 - 4 5 - 6'
textData:< 2031202d 20322033 20e28093 20342035 20e28094 203620>
newString:'1 - 2 3 - 4 5 - 6'
newStringData:< 2031202d 20322033 202d2034 2035202d 203620>