Reemplazar un char en NSString
-
01-10-2019 - |
Pregunta
QUIERO Sólo tiene que sustituir todos los occourrencies de "+" con un espacio en blanco "" char ... He intentado algunas ejemplo que aparece aquí, también se utiliza NSSMutableString, pero la caída del programa ... ¿cuál es la mejor manera de reemplazar un char de otro ?? gracias
Solución
Si desea reemplazar con una cadena mutable (NSMutableString) en el lugar:
[theMutableString replaceOccurrencesOfString:@"+"
withString:@" "
options:0
range:NSMakeRange(0, [theMutableString length])]
Si desea crear una nueva cadena inmutable (NSString):
NSString* newString = [theString stringByReplacingOccurrencesOfString:@"+"
withString:@" "];
Otros consejos
NSString *firstString = @"I'm a noob at Objective-C", *finalString;
finalString = [[firstString stringByReplacingOccurrencesOfString:@"O" withString:@"0"] stringByReplacingOccurrencesOfString:@"o" withString:@"0"];
¿Tienes un código de aquí !
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow