ios - Changing text entered by user into UITextView -
ios - Changing text entered by user into UITextView -
just playing around code practice more anything. i'm writing app users come in text uitextview, presses button , every word entered changed single word, defined program, keeping punctuation intact.
how achieved? thought of counting words , replacing them didn't work punctuation disappears.
any thoughts?
thanks,
this solution:
nsstring *inputstring = @"replace words! you?"; nsstring *substitutionstring = @"bla"; nsmutablestring *outputstring = [inputstring mutablecopy]; [outputstring enumeratesubstringsinrange:(nsrange){0, [outputstring length]} options:nsstringenumerationbywords usingblock:^(nsstring *substring, nsrange substringrange, nsrange enclosingrange, bool *stop) { [outputstring replaceoccurrencesofstring:substring withstring:substitutionstring options:0 range:substringrange]; }]; nslog(@"%@", outputstring); ios objective-c cocoa-touch
Comments
Post a Comment