Search code examples
iosobjective-cnsstringuppercaselowercase

Uniquely mapping upper case to lower case


I have 2 strings:

ahFkZXZ-cHV6emxlZmxvd2RldnIZCxILUHV6emxlSW1hZ2UYgICAgICAgIBcDA
ahFkZXZ-cHV6emxlZmxvd2RldnIZCxILUHV6emxlSW1hZ2UYgICAgICAgIBCDA

You'll notice that these 2 strings are nearly identical, other than the 3rd-to-last letter 'C' being upper-case in one, and lower-case in the other. I am saving files to disk based on these names - so the problem then becomes, since Mac OS X is a case-insensitive file system, the 2nd file with this name will overwrite the first.

My immediate thought is to iterate on the letters in the string, and 'map' the upper-case letters to lower case. For instance, for every upper case letter, replace it with 2 lower case letters ('C' would become 'cc').

Is there any problem with uniqueness in this implementation? What is the simplest way to accomplish this in Objective C? Iterating on each letter is easy enough, but I was curious if there were some built-in helper functions that might make this less painless.

Also I am not sure about file name length limitations on Mac OSX/iOS.

*Also note this is for an iOS app, but I only want to solve this because it bugs out in the simulator.


Solution

  • You are doing it wrong.

    Possible solution:

    1. convert the string to uppercase/lowercase
    2. if both "keys" are valid and you need two distinct files for them, don't use the key as the file name. Assign a unique (e.g. incrementing) file name and have a separate file mapping the key to file name.