How to replace a character in Objective-C String for iPhone SDK?

iOSiPhone/iPadMobile Development

To replace a character in objective C we will have to use the inbuilt function of Objective C string library, which replaces occurrence of a string with some other string that we want to replace it with.

To create a string in objective C we need to write −

NSString *str = @"tutori@als";

Now we have a choice of replacing characters in this string and creating new one, or modify this same string. In this example we will modify this string and print in the next line.

str = [str stringByReplacingOccurrencesOfString:@"@" withString:@""];
NSLog(@”%@”,str);

When we run the above code, str is replaced with “tutorials” which was previously “tutori@als”.

raja
Published on 21-Jan-2019 12:29:36
Advertisements