开发者

Insert a string to a string in Objective C

开发者 https://www.devze.com 2023-01-07 10:04 出处:网络
I need to insert a stri开发者_Python百科ng \'GMT\' into \"2010-07-13T11:22:33-07:00\" before the last \'-\' (it could also be a \'+\')

I need to insert a stri开发者_Python百科ng 'GMT' into

"2010-07-13T11:22:33-07:00"

before the last '-' (it could also be a '+') the result should be

"2010-07-13T11:22:33GMT-07:00"


Have a look at the NSString and NSMutableString documentation. I believe what you're looking for is something along the lines of the following (I haven't tested this code, but judging by the documentation it should work):

NSMutableString* date = @"2010-07-13T11:22:33-07:00";
NSRange r = [date rangeOfString:@"-" options:NSSearchBackwards];
[date replaceCharactersInRange: r withString: @"GMT-"];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号