• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

delete multiple line-break

Engaged ,
Oct 30, 2016 Oct 30, 2016

Copy link to clipboard

Copied

Hi.

I know, it is a basic thing. Theoretical I now the answer, but it doesn´t work.

I want to delete double line-breakes. Ishould work with the siple script:

app.findGrepPreferences.findWhat = "\\r\\r";  //or \\r{2,}

app.changeGrepPreferences.changeTo = "\\r";     

app.selection.paragraphs.everyItem().changeGrep(); 

If I search for them one by one, the´ll be found. Not as a double-pack!

???

TOPICS
Scripting

Views

525

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Oct 31, 2016 Oct 31, 2016

By definition a search on paragraphs won't find 2 \r as a paragraph is defined as until and including one \r (or end of story).

If you don't wont to search the entire story do.

app.selection[0].changeGrep();

or app.selection[0].texts[0].changeGrep();

Don't forget the [0] by the selection

HTH

Trevor

Votes

Translate

Translate
Community Expert ,
Oct 30, 2016 Oct 30, 2016

Copy link to clipboard

Copied

Line 3 is wrong. Try this:

app.selection[0].parentStory.changeGrep();

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

Ok Peter you are right. But I do not have this bug in my original code. I have made it shorter for this thread. It works, but just by searching for one line-breake. If I search for two of them nothing happens, not even an error-alert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

By definition a search on paragraphs won't find 2 \r as a paragraph is defined as until and including one \r (or end of story).

If you don't wont to search the entire story do.

app.selection[0].changeGrep();

or app.selection[0].texts[0].changeGrep();

Don't forget the [0] by the selection

HTH

Trevor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

That´s it!

Now I can see it clearly, of course.

Thank you (all) for the hint.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 01, 2016 Nov 01, 2016

Copy link to clipboard

Copied

Hi Trevorׅ,

I think it is ok when the following style is same as the previous. If not it overrides the following para style. Is there anyway to retain them as is??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 01, 2016 Nov 01, 2016

Copy link to clipboard

Copied

LATEST

app.findGrepPreferences.findWhat = "\\r+\\r";  //or \\r{2,} 

app.changeGrepPreferences.changeTo = "\\r";       

app.selection[0].changeGrep();

Seems to work for me

Screen Shot 2016-11-01 at 14.45.49.png

Screen Shot 2016-11-01 at 14.46.09.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

Something in your original code may interfere with what you're trying to do and lead to the behaviour that you see. But your 3-line snippet behaves as it should. The line

app.selection[0].paragraphs.everyItem().changeGrep()

looks for two or more \r in each paragraph, and a paragraph cannot contain more than one \r. That's why looking for \r wors and looking for \r\r does not. To find multiple \r have to target the story, not individual paragraphs.

P.

(Trevor beat me to it)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines