Sort lines of a txt file by lenght of the stringWith 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');