以下是我的代码:
NSString *str = [EpiC objectAtIndex:indexPath.row];
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"\/"];
str = [[str componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @"\"];
NSLog(@"%@", str);
显示错误如下: 这一行的未知逃逸序列:
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"\/"];
和意想不到的' @'在计划中,在这一行:
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"\"];
答案 0 :(得分:2)
未知转义序列表示必须使用第二个反斜杠转义反斜杠。
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"\\/"];
额外的反斜杠也解决了意外'@'程序错误。
答案 1 :(得分:1)
喜欢
NSString *str = @"FSJ\/6356232";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"\\/"];
str = [[str componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @"\\"];
NSLog(@"%@", str);
你得到了
的输出答案 2 :(得分:-1)
请按照以下步骤确定为您工作。
NSString *str = @"FSJ\/6356232";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"\\/"];
str = [[str componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @"\\"];
NSLog(@"%@", str);