简体   繁体   中英

Cant replace string in NSMutableString

This is my string:

2011-10-07T08:55:16-05:00

I am trying to remove the colon with this code:

NSRange range = NSMakeRange(dateString.length-3, 1);
NSString *temp = [dateString substringWithRange:range];
if ([temp isEqualToString:@":"])
    [dateString replaceCharactersInRange:range withString:@""];

My code enters the if statement, so I know that it found the colon. But it crashes with no errors on the last line. What am I doing wrong?

try this :

NSMutableString *dateString = [NSMutableString stringWithString:@"2011-10-07T08:55:16-05:00"];

NSRange range = NSMakeRange(dateString.length-3, 1);
NSString *temp = [dateString substringWithRange:range];
if ([temp isEqualToString:@":"])
    [dateString replaceCharactersInRange:range withString:@""];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM