• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UTF16 character in NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UTF16 character in NSString


  • Subject: Re: UTF16 character in NSString
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 10 Mar 2007 07:24:30 -0800


On Mar 10, 2007, at 1:44 AM, Ivan C Myrvold wrote:

I am reading data from a SOAP webservice, where a hyphen divider is represented as UTF16Char 32000 (decimal).
I found a way to strip those hyphen characters in NSString with this method:


- (NSString *)stripHyph:(NSString *)str {
int i, count = 0, len = [str length];
NSMutableString *mutstr = [NSMutableString stringWithString:str];
UTF16Char hyph = 32000;

for (i=0; i<len; i++)
if ([str characterAtIndex:i] == hyph)
[mutstr replaceCharactersInRange:NSMakeRange(i + count--, 1) withString:@""];
return mutstr;
}


But I also needs to do the other way around, and inject UTF16Char into an NSString where I want, but I don't know how I can do that.

Can anyone give me some help here?

You should be able to use -[NSString replaceOccurrencesOfString:withString:options:range:] instead of your loop above since you appear to want to replace all of them. Just construct an NSString with the character you want to replace.


To do that consider the following...
NSString* hyphString = [NSString stringWithCharacters:&hyph length:1];

Also for the following...
NSMutableString *mutstr = [NSMutableString stringWithString:str];
...consider...
NSMutableString *mutstr = [str mutableCopy];

Finally note -[NSMutableString insertString:atIndex:] as a way to insert characters/strings at particular locations in a string.

-Shawn
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >UTF16 character in NSString (From: Ivan C Myrvold <email@hidden>)

  • Prev by Date: PDFView setDocument: autorelease crash?
  • Next by Date: Core Data and Undo action names
  • Previous by thread: UTF16 character in NSString
  • Next by thread: NSMenuItem events
  • Index(es):
    • Date
    • Thread