Replace U+2028 linefeed

Hi all

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.

Thanks I will try some things to see if I got it working with the mail content, have a great day

Can’t get it to work but I am sure it is me

I want to replace the U+2028 character in SetMailContent

set SetMailContent to content of MailInloop
set formula of range (“D” & MyRow) of DestSheet to SetMailContent

I can do it now in Excel but that is not so easy, I hope it is easy in Applescript.
So I got it working but love to have another way to do it.

Greetings from the Netherlands

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

character id 8232 is the equivalent of the linefeed 2028 character.

1 Like

Amazing Stefan, this is working for me, in Excel VBA it is not so easy.

Thanks for your time and always be helpful in this forum :+1:

	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
1 Like

Thanks I got this working also, got two good solutions now, thanks for your time.

Greetings, Ron