• 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: Init an NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Init an NSString


  • Subject: Re: Init an NSString
  • From: Pascal Goguey <email@hidden>
  • Date: Sat, 21 Dec 2002 10:55:06 +0900

Hello!

Thanks for your reply!

[problem initializing string deleted]

> I got bitten by this recently, and there was a short thread on this
> list
> (check the archives at cocoa.mamasam.com) about it.
>
> Basically you can only construct NSStrings at compile-time using the
> @"..."
> notation that contain 7-bit characters. Probably US-ASCII.
>
> You've got two options - the first is to use something like localized
> strings - the syntax of those files has an escape sequence allowing
> Unicode
> to be entered even in ASCII files, though you can also have the whole
> file
> written in Unicode and encoded in UTF-8.
>
> The second is to build your static strings as arrays of unichar, and
> build
> NSStrings from those at run-time (NSString
> -initWithCharacters:length:).
> That suited my app better than using localizable.strings.
>
> Actually there's a 3rd option - work out the UTF-8 encoding of your
> string
> and embed those bytes in your NSString using \x (I can't remember if
> that's
> the escape sequence or not, but I mean the one that lets you embed
> arbitrary
> bytes in the string) but I think that makes your code pretty
> unreadable and
> your strings become hard to change.

In the meantime, I got a very simple solution (Thanks Eric!).

To summarize, S is an UTF-8 string I read from a file.

NSString * Prefix = [NSString stringWithUTF8String:"My non-ascii
string"];
BOOL result = [S hasPrefix:Prefix];

That's it!

This is by far the shortest way to do what I wanted.

By the way, now my file parser works.
For those who may wonder if MacOS-X's native development environment
is suitable for their project, I would like to say that in my opinion,
it has been
the fastest startup I have ever experienced. Well, I don't want to
pretend I
did anything complicated, but I wrote my file parser within less than
one week
on my spare time without any prior knowledge in Obj-C.

Thanks,

Pascal
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Init an NSString (From: Chris Ridd <email@hidden>)

  • Prev by Date: Finding Applications for File Type
  • Next by Date: Increasing a cell's height!!! HELP!
  • Previous by thread: Re: Init an NSString
  • Next by thread: Dialogs and NIB's
  • Index(es):
    • Date
    • Thread