• 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: Multiline srings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiline srings


  • Subject: Re: Multiline srings
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 17 Feb 2009 22:18:23 -0600

On Feb 17, 2009, at 9:52 PM, Jay Kickliter wrote:

I need to embed an NSString into a command tool. It is a template for a file that will be filled in with data from input files. I've been scouring the web and I can't find anything about declaring multi-line objective-c strings. Is there any way to avoid having to manually?

Here's just the first few lines:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2";>
 <Document>
   <name>%@</name>
   <Style id="%@">
     <LineStyle>
       <color>7f00ffff</color>

Do I have to manually conver it to @"<?xml version=\"1.0\" encoding= \"UTF-8\"?>\n<kml xmlns=\"http://earth.google.com/kml/2.2\";>" etc....? Or is there some way to keep in multi-line for clarity?

You can put the text into a file in your bundle's resources, and load it from there at run time. Judging from your content, this seems like the best approach.


If you really want to compile it into the C or Objective-C code, then you do have to express the newlines with \n. However, you can split the string across multiple lines using the fact that two string literals encountered in a row are merged by the compiler. That is, this:

	NSString* foo = @"This string has\ntwo lines.\n";

is equivalent to this:

	NSString* foo = @"This string has\n"  "two lines.\n";

or this:

	NSString* foo = @"This string has\n"
					"two lines.\n";

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: 
 >Multiline srings (From: Jay Kickliter <email@hidden>)

  • Prev by Date: Re: display unicode string one character at a time, not at simple as it seems
  • Next by Date: RE: Adding Multiple NSWindow or NSPanel into another NSWindow
  • Previous by thread: Multiline srings
  • Next by thread: NSMailDelivery API
  • Index(es):
    • Date
    • Thread