Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何编辑此字符串_Iphone_String - Fatal编程技术网

Iphone 如何编辑此字符串

Iphone 如何编辑此字符串,iphone,string,Iphone,String,这是一根绳子 "Level1, Row 1, Gold, Seat no 7". "Level1, Row 1, Gold, Seat no 8". Name: Karan. 我正试着把这根绳子做成这样 Level1, Row 1, Gold, Seat no 7, Level1, Row 1, Gold, Seat no 8, Name: Karan 我必须在此搜索座位号和姓名,在此之前,我需要在数组中分隔此座位号和姓名。 这就是我尝试的方式 [outStr stringByReplac

这是一根绳子

 "Level1, Row 1, Gold, Seat no 7". "Level1, Row 1, Gold, Seat no 8". Name: Karan.
我正试着把这根绳子做成这样

Level1, Row 1, Gold, Seat no 7, Level1, Row 1, Gold, Seat no 8, Name: Karan
我必须在此搜索座位号和姓名,在此之前,我需要在数组中分隔此座位号和姓名。 这就是我尝试的方式

[outStr stringByReplacingOccurrencesOfString:@"." withString:@","];
//[outStr stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSLog(@"outstr:%@", outStr);
NSArray *arrSplit1 = [outStr componentsSeparatedByString:@","];
NSString *stringToSearch = @"seat no";
NSString *stringToSearch1 = @"name";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c]    %@",stringToSearch]; 
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",stringToSearch1];
NSArray *results = [arrSplit1 filteredArrayUsingPredicate:predicate];
NSArray *results1 = [arrSplit1 filteredArrayUsingPredicate:predicate1];
NSLog(@"results:%@", results);
NSLog(@"results:%@", results1);

我如何才能做到这一点,请指导。

使用NSString的这种方法

- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement

使用NSString的这种方法

- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement

像这样试试它会给出正确的输出

NSString *stringURL = @"Level1, Row 1, Gold, Seat no 7\". \"Level1, Row 1, Gold, Seat no 8\". Name: Karan.";
    stringURL=[stringURL stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    stringURL=[stringURL stringByReplacingOccurrencesOfString:@"." withString:@","];
    if([stringURL hasSuffix:@","])
        stringURL=[stringURL substringToIndex:[stringURL length]-1];
    NSLog(@"%@",stringURL);
O/p:-


在您的代码中,将
\“
替换为

这样做会给出正确的输出

NSString *stringURL = @"Level1, Row 1, Gold, Seat no 7\". \"Level1, Row 1, Gold, Seat no 8\". Name: Karan.";
    stringURL=[stringURL stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    stringURL=[stringURL stringByReplacingOccurrencesOfString:@"." withString:@","];
    if([stringURL hasSuffix:@","])
        stringURL=[stringURL substringToIndex:[stringURL length]-1];
    NSLog(@"%@",stringURL);
O/p:-


在您的代码中,将
\“
替换为

@iPhone:根据您的要求,您可以在我的代码中使用stringURL字符串替换字符串。@iPhone:根据您的要求,您可以在我的代码中使用stringURL字符串替换字符串。我想您有这三个字符串1。“级别1,第1行,金色,7号座位”2。“1层,第一排,黄金座,8号”3。“姓名:卡兰”。我说得对吗?@DharmbirChoudhary只是扫描车票时得到的一根线。这是我得到的完整的字符串。我想你得到了你的答案,所以需要解释一下。我想你有这三个字符串1。“1级,1排,黄金,7号座位”2。“1层,第一排,黄金座,8号”3。“姓名:卡兰”。我说得对吗?@DharmbirChoudhary只是扫描车票时得到的一根线。这是我得到的完整字符串。我想你得到了答案,所以需要在其中进行解释。。