Applescript:带变量的文本(删除缺失的变量)

时间:2016-09-21 07:16:38

标签: variables text applescript missing-data

我有一个保存文本文件的脚本:

将myNote设置为"     文本     文本     文本

more text: " & variable 1 & "

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

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

"问题"是变量有时是空白的,所以我在文本之间有一些空白

喜欢:

  

更多文字:变量1

     

变量3

     

更多文字....变量5

如果变量没有值,我该如何删除空白行?

我应该将变量设置为缺失值而不是#34; "或者会这样做?

我的第二个想法是

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 & "

将备注设置为note1& note2和note3

1 个答案:

答案 0 :(得分: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