Removing Blank Lines

Howdy, All–

I have the following code to remove selected lines from a file:

	repeat with each line of epsData
		put it into theLine
		if theLine contains "%%Title" 
			delete theLine from epsData
		else if theLine contains "%%Creator:" 
			delete theLine from epsData
		else if theLine contains "%%CreationDate" 
			delete theLine from epsData
		else
		end if
	end repeat

Works great, however I now have blank lines in the file. Any ideas on how I can squeeze these out or modify the above command to ensure no blank lines exist?

Thanks!
Allen

Have you tried this:


 repeat with each line of epsData
      put it into theLine
      if theLine contains "%%Title"
         delete theLine from epsData
      else if theLine contains "%%Creator:"
         delete theLine from epsData
      else if theLine contains "%%CreationDate"
         delete theLine from epsData
      else if theLine is empty
        delete line repeatIndex() of epsData
      end if
 end repeat

When you’re iterating through things (lines, in your case) that you may want to modify or delete, I suggest using “by reference” which allows SenseTalk to refer back to the line in the source value:

repeat with each line theLine of epsData by reference 
      if theLine contains "%%Title" 
         delete theLine 
      else if theLine contains "%%Creator:" 
         delete theLine
      else if theLine contains "%%CreationDate" 
         delete theLine 
      end if 
end repeat

I think that will do what you want.

You also may want to try this example out…


put <<PS>> into psData

-- add your tokens here to delete
set tokens to ( "%%Title:", "%%Creator:", "%%CreationDate:" )

-- delete the line if it starts with a token
repeat with each line in psData by reference
        if word 1 of it is in tokens then delete it
end repeat

put psData

please delete this message

please delete this message

please delete this message