Re: Unicode replaceOccuranceOfString?
Re: Unicode replaceOccuranceOfString?
- Subject: Re: Unicode replaceOccuranceOfString?
- From: Ali Ozer <email@hidden>
- Date: Sun, 19 Sep 2004 01:40:56 -0700
Unless I am misunderstanding your question, you should be able to do something like:
unichar u[1] = {0x2014}; // I think em-dash is 0x2014
NSString *emdash = [NSString stringWithCharacters:u length:sizeof(u) / sizeof(unichar)];
[myString replaceOccurrencesOfString:emdash withString:@"---" options:0 range:range];
without bothering with a strings file. Depending on how large the target string is, you can declare u[] to be as large as you want and put the appropriate unichars in there. Note that the simple case of a one character string can also be done with:
unichar u = 0x2014;
NSString *emdash = [NSString stringWithCharacters:&u length:1];
and another (less efficient but convenient) way is:
NSString *emdash = [NSString stringWithFormat:@"%C", 0x2014];
Ali
Begin forwarded message:
From: Rachel Blackman <email@hidden>
Date: September 18, 2004 23:42:22 PDT
To: email@hidden
Subject: Unicode replaceOccuranceOfString?
I have a situation wherein I would like to accept if someone pastes in various characters (such as the Unicode ellipse or emdash, or single or double quotes which have directions to them) which cannot be represented in ASCII, and translate them to their seven-bit-safe equivalents.
Unfortunately, I am at a complete loss on a way to do this. There is no way to encode non-7-bit characters in a string literal, as I know, but for whatever reason, NSLocalizedStringFromTable doesn't seem to work. I have to index by some kind of code (such as 'suh-emdash' for 'stupid Unicode hack: mdash) and for whatever reason, I still get 'suh-emdash' as my string. And yet unipunc.strings is in the English.lproj directory of my finalized .app... so I'm at a bit of a loss.
Further, it seems there must be a better way to do replacements of a few specific characters which simply don't happen to be 7-bit-safe...! Any advice would be very welcome...
--
Rachel 'Sparks' Blackman -- sysadmin, developer, mad scientist
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden