-(NSString *)replace:(NSString *)input with:(NSString *)newHex
{
NSArray *seperated = [input componentsSeparatedByString:@"_"];
return [NSString stringWithFormat:@"%@_%@.png", [seperated objectAtIndex:0], newHex];
}
Simple Objective C String manipulation
-
24-06-2023 - |
Question
I have file names in the following format
filename_ffffff.png
filename2_cccccc.png
...
How can I manipulate this string and replace its hex value with a value of my choosing.
say the new value is fffccc
which would take filename_ffffff.png
and turn it into filename_fffccc.png
-(NSString *)replace:(NSString *)input with:(NSString *)newHex{
//find in input a patern of 6 char hex followed by dot png
// remove it from the string
// add the newHex followed by png
}
La solution
Autres conseils
Do you mean
newstring = [oldstring stringByReplacingOccurrencesOfString:@"ffffff.png" withString:@"cccccc.png"];
It looks like you need to change the occurrence of the string value. Check this :
NSString *Str = [yourString stringByReplacingOccurencesOfString:@"ffffff.png" withString:@"fffccc"];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow