I would like to wipe a NSString object in my code (replace every characters by 0).
To do that I tried this :
NSString *myString;
for (int i=0; i<[myString length]; i++)
{
myString[i] = 0;
}
But it doesn’t compile : “Incompatible types in assignment” at line myString[i] = 0;
I understand, but I can’t use function stringByReplacingOccurancesOfString because it creates a new object and I would like to replace characters in my first object.
Any help ?
NSStringis immutable, meaning that you can not change its contents once its created. You have NSMutableString for that purpose.Also, you can not access the characters in a
NSStringorNSMutableStringwith this syntax:NSStrings andNSMutableStrings are objects and you work with objects by sending messages to them. For instance, you havecharacterAtIndex:method that returns the character at the given index, orNSMutableString‘sreplaceOccurrencesOfString:withString:options:range:that replaces all occurrences of a given string in a given range with another given string.