ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Sort lines of a txt file by lenght of the string

<< < (7/7)

AbteriX:
Sort lines of a txt file by lenght of the string

With pure JavaScript and a TextEditor supporting WSH scripting.

NewText = (OldText().split("\n")).sort(function(a,b){return b.length-a.length}).join('\n');



PSPad

--- ---//X:\PSPad\Script\JScript\Sort.js
module_name = "StefanSort";
module_ver = "0.001a";
function Init(){
  addMenuItem("Sort Random"                        ,"Sort", "StefanSortRandom");
  addMenuItem("Sort by line length (Long to short)","Sort", "StefanSortByLineLengthDown");
  addMenuItem("Sort by line length (Short to Long)","Sort", "StefanSortByLineLengthUp");
}
function StefanSortRandom() {
  var objEditor = newEditor();
  objEditor.assignActiveEditor();
  objEditor.Text((objEditor.Text().split("\n")).sort(function(){return .5 - Math.random()}).join("\n").slice(0, -1));
}
function StefanSortByLineLengthDown() {
  var objEditor = newEditor();
  objEditor.assignActiveEditor();
  objEditor.Text((objEditor.Text().split("\n")).sort(function(a,b){return b.length-a.length}).join('\n').slice(0, -1));
}
function StefanSortByLineLengthUp() {
  var objEditor = newEditor();
  objEditor.assignActiveEditor();
  objEditor.Text((objEditor.Text().split("\n")).sort(function(b,a){return b.length-a.length}).join('\n').slice(0, -1));
}


EmEditor:

--- ---document.selection.text = ((document.selection.text.split("\n")).sort(function(a,b){return b.length-a.length})).join('\n');


 

Contro:
Problem solved.
I have tried some of the above help with good result.
 :-[

Navigation

[0] Message Index

[*] Previous page

Go to full version