I read mail content into an Excel workbook but have a problem with the linefeed 2028 character.
Can I change this to another character so I can split the content in Excel into different columns.
I have problems in Excel to do this so maybe it is easy to do it in AppleScript
Thanks for reading this
Greetings from the Netherlands
The U+2028 character is actually called the line separator.
Note that the site seems to remove this character so I’ve used regular line feeds instead. Replacing each linefeed with character id 8232 is one approach to take. For the output, I’ve included three separators that are commonly used in excel but use whatever you like.
-- set orig to the clipboard
set orig to "text string one
text string two
text string three"
-- split text on line separator character
set delim1 to character id 8232 -- line separator
set text item delimiters to delim1
set tis to text items of orig
--> {"text string one", "text string two", "text string three"}
-- substitute other character and re-join
set text item delimiters to tab
set newt to tis as text
--> "text string one text string two text string three"
set text item delimiters to ";"
set newt to tis as text
--> "text string one;text string two;text string three"
set text item delimiters to ","
set newt to tis as text
--> "text string one,text string two,text string three"
You can use this script to make the change. Set delimiters to linefeed to split the text, and then to character id 8232 to rejoin the text.
This AppleScriptObjC code replaces any line separator character U+000A ~ U+000D , U+0085 , U+2028 , and U+2029 with a linefeed U+000A character.
It’s actually a more sophisticated version of replacing text with text item delimiters
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
set theText to "line one" & character id 8232 & "line two" & character id 8232 & "line three"
set nsText to current application's NSString's stringWithString:theText
set newLinesCharacterSet to current application's NSCharacterSet's newlineCharacterSet()
set separatedLines to nsText's componentsSeparatedByCharactersInSet:newLinesCharacterSet
set lineFeedSeparatedParagraphs to (separatedLines's componentsJoinedByString:linefeed) as text
Note: character id 8232 is the equivalent of the linefeed 2028 character.
set theText to "line one" & character id 8232 & "line two" & character id 8232 & "line three"
set AppleScript's text item delimiters to {linefeed, character id 8232}
set final to text items of theText as text