2

placemark.subThoroughfare 当我搜索一个位置时,有时我会从如何将该符号重新格式化为正常的“-”中获取此字符串?

在此处输入图像描述

非常感谢您的回答

4

1 回答 1

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:-<br> emDashCharacter:-<br> textString:'1 - 2 3 - 4 5 - 6'
textData:<2031202d 20322033 20e28093 20342035 20e28094 203620> newString
:'1 - 2 3 - 4 5 - 6 '
新字符串数据:<2031202d 20322033 202d2034 2035202d 203620>

于 2013-01-01T16:24:46.700 回答