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

Code to be evaluated! [014] Words reversed in each para! …

LEGEND ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

Hi Scripters,

Some misunderstanding! ... I can't find my error:

var mySel = app.selection[0],

myParas = mySel.contents.split("\r"),

P = myParas.length;

for ( var p = 0 ; p < P-1 ; p++ )

    {

        var myPara = myParas

;

        myWords = myPara.split(" ");

        myNewWords = myWords.reverse();

        myPara = myNewWords.join(" ");

    }

myNewParas = myParas.join("\r");

mySel.contents = myNewParas;

I have selected several paras and I would like to reverse the words per each para!

Thanks in advance! 

(^/)

TOPICS
Scripting

Views

305

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

Enthusiast , Jan 16, 2017 Jan 16, 2017

Hi,

Quick debug ... 🙂

var myNewParas = []; // declare  array

var mySel = app.selection[0], 

myParas = mySel.contents.split("\r"), 

P = myParas.length; 

for ( var p = 0 ; p < P ; p++ )  // P not P-1, if not the last para will be ignored

    { 

        var myPara = myParas

        myWords = myPara.split(" ");

        myNewWords = myWords.reverse(); 

        myNewParas.push( myNewWords.join(" ")); // push line with reverse words in array

    } 

myNewParas = myNewParas.join("\r"); 

mySel.contents = m

...

Votes

Translate

Translate
Enthusiast ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

Hi,

Quick debug ... 🙂

var myNewParas = []; // declare  array

var mySel = app.selection[0], 

myParas = mySel.contents.split("\r"), 

P = myParas.length; 

for ( var p = 0 ; p < P ; p++ )  // P not P-1, if not the last para will be ignored

    { 

        var myPara = myParas

        myWords = myPara.split(" ");

        myNewWords = myWords.reverse(); 

        myNewParas.push( myNewWords.join(" ")); // push line with reverse words in array

    } 

myNewParas = myNewParas.join("\r"); 

mySel.contents = myNewParas;

Regards

Ronald

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
LEGEND ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

LATEST

Cool!

Thanks Ronald! 

(^/)

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