2016-09-21 36 views
0

我有被保存爲文本文件的腳本:AppleScript的:用可變文本(刪除丟失的變量)

集myNote爲「 文本 文本 文本

more text: " & variable 1 & " 

" & variable 2 & " 
" & variable 3 & " 
" & variable 4 & " 

More text .... 
" & Variable 5 & " 

的‘問題’是該變量是一段空白,所以我有文字

之間等幾個空行:

更多的文字:變量1

變量3

更多的文字....變量5

我如何刪除空行如果變量有沒有價值?

我應該將變量設置爲缺少值而不是「」,或者會這樣做嗎?

二的想法,我已經是

If variable1 is not = to " " then 
Set note1 to variable1 
End if 

設置

note1 to 
Text 
    Text 
    Text 

Set note2 to  
    more text: " & variable 1 & " 

Set note3 to  
    " & variable 2 & " 

設置音符注1 &注2和注3

回答

0

,如果你試圖讓「myNote」爲變量的文本如果變量只是「」然後不留空行,你可以使用這樣的東西:

set myNote to "Text Text Text" & return 

if variable1 is not "" then 
    set myNote to myNote & return & variable1 
end if 
if variable2 is not "" then 
    set myNote to myNote & return & variable2 
end if 
if variable3 is not "" then 
    set myNote to myNote & return & variable3 
end if 
if variable4 is not "" then 
    set myNote to myNote & return & variable4 
end if 
if variable5 is not "" then 
    set myNote to myNote & return & "More Text .... " & variable5 
end if