2010-11-03 24 views
2

我的部分代碼會將HTML代碼輸出到文件中。我有一個標題,將在所有文件的開頭加蓋。我想將其聲明爲:Xcode 3.2.4 - 如何分割多行的代碼

NSString *myHeader = @" 
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n 
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n 
\n 
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n 
    <head>\n 
    <meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />\n 
    <meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\">\n 
     <title>My Title</title>\n 
    <link rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/opensearch.xml\" title=\"GitHub\" />\n 
    <link rel=\"fluid\" href=\"http://mysite.com/fluid.png\" title=\"fluid\" />\n 
"; 

很顯然,我躲過了報價,但即使這樣做,Xcode不是喜歡上幾行此字符串聲明蔓延。如果可能的話,我想保持這種方式,而不是將其加入難以閱讀和改變的長線。

我該怎麼做?

謝謝。

回答

7

像這樣:

NSString *myHeader = @"text here" 
    @"more text here" 
    @"even more text here" 
    @"still more text"; 
+0

人,你是一個天才!!!!!我絕不會想到在一千年內...我知道你的暱稱說明這很明顯,但對我來說不是這樣!謝謝!!!! – SpaceDog 2010-11-03 19:32:18

+0

謝謝,這個名字只是一個笑話,對提問者沒有任何反思。 – Anna 2010-11-03 19:34:59

+0

是的,我知道...:D – SpaceDog 2010-11-03 19:41:57

3

這工作在Xcode:

const char *val = "Hello world" 
        "this is me";