Skip to main content
Mohamed Hameed21513110
Inspiring
September 26, 2022
Answered

Delete white space and line numbering

  • September 26, 2022
  • 1 reply
  • 419 views

Greetings to all

I want a script that removes the white space at the beginning of each line

Number each line at the beginning of each line

 

 

 

I attached a psd file to the text to illustrate the idea

This topic has been closed for replies.
Correct answer jazz-y

 

var s = activeDocument.activeLayer.textItem.contents.split('\r');
for (var i=0; i<s.length; i++) s[i] = s[i].replace(/^\s+/, i+1 + '/ ');
activeDocument.activeLayer.textItem.contents = s.join('\r');

 

1 reply

jazz-yCorrect answer
Legend
September 26, 2022

 

var s = activeDocument.activeLayer.textItem.contents.split('\r');
for (var i=0; i<s.length; i++) s[i] = s[i].replace(/^\s+/, i+1 + '/ ');
activeDocument.activeLayer.textItem.contents = s.join('\r');

 

Mohamed Hameed21513110
Inspiring
September 26, 2022

@jazz-y 

Thank you very much for your interest and cooperation