在ios应用中移除“\”符号
2014-04-27 来自:cal 1 人回应

在json反响中获取了url字符串,其中有反斜杠。我想删除这些\符号。

我写的代码没有实现:

NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
    NSString* encodedString = [responseData stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSLog(@"Response ==> %@" ,encodedString);

       // here encodedString is a url which is showing crctly in output and need to trim the \ character.

       // NSString* str = [NSString stringWithFormat: @"encodedString"];
       // str = [str stringByReplacingOccurrencesOfString:@"?" withString:@""];
       // NSLog(@"Response ==> %@" , str);

    encodedString = [encodedString stringByReplacingOccurrencesOfString:@"\\" withString:@""];
        NSLog(@"Response ==> %@" ,encodedString);

请高手指点,谢谢。

2014-05-11 来自:眼迹。

试试:

NSMutableString *string=[NSMutableString stringWithString:@"hi this i\\s good"];
//NSMutableString *string=[NSMutableString stringWithString:encodedString];

[string replaceOccurrencesOfString:@"\\" withString:@"" options:1 range:NSMakeRange(0, string.length)];

NSLog(@"%@",string);

您的回应

你还未登陆,不能回应!登陆