I've been trying to find a better way to switch on each character of a string.
My existing code is:
NSUInteger len = [oldName length], i;
SEL xSelector = @selector(characterAtIndex:);
unichar (*charAtIdx)(id, SEL, NSUInteger) = (typeof (charAtIdx)) [oldName methodForSelector:xSelector];
NSMutableString *NewName = [NSMutableString new];
for (i=0 ; i<len ; i++){
unichar c = charAtIdx(oldName,xSelector,i);
if (c == "Ú" || c == "°"){
[NewName appendString:@"s"];
}
else if (c == "Û" || c == "”"){
[NewName appendString:@"s"];
}
else if (c == "◊" || c == "˜"){
[NewName appendString:@"x"];
}
else blablabla
}
return NewName;
Now, the above seems to be working, however i have about 50 if statements that "switch" mainly extended ASCII codes (character codes 128-255) to more meaningful ones.
I thought about using a switch statement with a typedef enum and switch on that, however, the below doesn't work:
typedef enum {·,¡,Ê,∆} ExtendedASCII;
The idea would be to replace "unichar c = charAtIdx(oldName,xSelector,i);" with the below:
ExtendedASCII c = charAtIdx(oldName,xSelector,i);
Switch c
case 0: //being ·
case 1: // being ¡
blablabla
Any ideas????
thanks, alex