Replacing carriage returns that break sentences.

Hello,

I am looking for a way to “de-columnize” some text. So I have text like this:
Hello, my name is
Doug. I am looking
for a way to fix a
problem with text.
Thank you for your
help.

That needs to look like this:
Hello, my name is Doug. I am looking for a way to fix a problem with text.
Thank you for your help.

If you’ll notice, the second and third sentence remain separated by a return. So I want to be able to replace “(any letter) & (the carriage return)” with “(a single space) & (the carriage return)”.
This solution will allow me to flow the text without removing the returns at the end of sentences (which often need to remain).

I have my find-and-replace script in action already on this script, so I guess I could just use that, but I don’t know how AS handles carriage returns.

I tried:
findAndReplace(“s” & return, " ", thefile)
…this script works otherwise (will replace the “s” with a space if I remove the “& return”.

So what do I use instead of “return”?

Thanks!

EDIT:
Found it! ASCII character 10… The worst part is I found it in a script that I wrote just3 months ago. I need more coffee. :wink:

Hi Doug,

one possible solution is the following script.
it adds a return character if the paragraphs ends with a dot
and filters double spaces

set a to "Hello, my name is
Doug. I am looking 
for a way to fix a 
problem with text.
Thank you for your
help."

set b to paragraphs of a -- paragraphs as list

set c to ""
repeat with i in b
	set c to c & i & space
	if i ends with "." then set c to c & return
end repeat
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to space & space
set c to text items of c -- check double spaces
set AppleScript's text item delimiters to space
set c to c as text
set AppleScript's text item delimiters to oldDelims

Ooooh… :cool:

Thanks for the tip. That may be a much more elegant solution than the one I’ve used.

Thanks again.