Re: Multiline srings
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