在 Cocoa 中,我想将包含特殊字符的字符串作为参数传递给 NSTask,但是该任务没有得到正确的字符串。
NSString *city=@"Zürich"; // This is the string with a special character
[arguments addObject:[NSString stringWithFormat:@"-iptc:city=%@",city]];
NSTask *task=[NSTask new];
[task setLaunchPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"exiftool"]];
[arguments addObjectsFromArray:[NSArray arrayWithObjects:@"-L",@"-overwrite_original_in_place",@"filename", nil]];
[task setArguments:arguments];
[task setStandardOutput:[NSPipe pipe]];
[task launch];
该任务不是以 Zürich 作为论据,而是 Zürich。知道如何正确传递带有特殊字符的字符串吗?我试过 UTF8String 但没有成功。谢谢。