Search code examples
iosstringnsstringcstring

Replace characters in C string


Given this C string:

unsigned char *temp = (unsigned char *)[@"Hey, I am some usual CString" UTF8String]

How can I replace "usual" with "other" to get: "Hey, I am some other CString".

I cannot use NSString functions (replaceCharactersInRange/replaceOccurencesOfString, etc.) for performance reasons. I have to keep it all at low level, since the strings I'll be dealing with happen to exceed 5MB, and therefore the replacements (there will be a lot of replacements to do) take about 10 minutes on a iOS device.


Solution

  • Objective-C is a just thin layer over C. If you need to work with native C strings, just go ahead and do it.

    This

    What is the function to replace string in C?

    seems to address your problem fairly well.