• 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: Working with Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Working with Strings


  • Subject: Re: Working with Strings
  • From: Brian Webster <email@hidden>
  • Date: Sun, 15 Jul 2001 13:41:36 -0500

on 7/15/01 1:56 AM, email@hidden at
email@hidden wrote:

> 1. Can I compare the return value of NSString characterAtIndex:
> with a normal character constant? i.e. will
>
> if( [ myString characterAtIndex:0 ] == 'a' ) ...
>
> evaluate correctly? If not, how can I compare characterAtIndex: with a
> constant?

The characterAtIndex: returns a two-byte Unicode character value. For most
ASCII characters, you can compare them to the ASCII char cast to a unichar,
and that will work. So:

if([myString characterAtIndex:0] == (unichar)'a') ...

I don't know the details of the compatibility between ASCII and the first
255 values of Unicode. If you do some funky characters (high ASCII, etc.),
you probably want to check the Unicode spec at unicode.org to find exact
Unicode values.

> 2. What's the easiest way to append a single character to an
> NSString? For constants, I'm using appendString: @"<character". What's
> the simplest way to do this with variables?

unichar myCharacter;
NSMutableString *myString;

[myString appendString:[NSString stringWithCharacters:&myCharacter
length:1]];

--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster/


  • Prev by Date: Bug in NSLog; program to verify included.
  • Next by Date: Re: Disabling some compiler warnings
  • Previous by thread: Re: Working with Strings
  • Next by thread: today's bug (?): getFileSystemInfoForPath
  • Index(es):
    • Date
    • Thread