Remove double quotes from NSString

前端 未结 6 555
长情又很酷
长情又很酷 2020-12-18 08:28

How do I remove double quotes from an NSString. Example:

//theMutableString: \"Hello World\"

[theMutableString replaceOccurrencesOfString:@\"\\\"\" withStr         


        
6条回答
  •  无人及你
    2020-12-18 09:32

    Assuming the mString bit is a typo. I ran this code and the answer was as expected

    NSMutableString * theMutableString = [[NSMutableString alloc] initWithString:@"\"Hello World!\""];
    NSLog(@"%@",theMutableString);
    
    [theMutableString replaceOccurrencesOfString:@"\"" withString:@"" options:NSCaseInsensitiveSearch range:(NSRange){0,[theMutableString length]}];
    
    NSLog(@"%@",theMutableString);
    
    [theMutableString release];
    

    Output

    2010-01-23 15:49:42.880 Stringtest[2039:a0f] "Hello World!"
    2010-01-23 15:49:42.883 Stringtest[2039:a0f] Hello World!
    

    So it mString was a typo in your question, then your code is correct and the problem is elsewhere. If mString is a typo in your code than that would be the issue.

提交回复
热议问题