A workaround.
Often, I want to do something with selected text in a file, regardless of its encoding. I only know that it only contains characters of the Latin-1 character set.
Since text usually doesn't contain the null byte, and a Latin-1 char x is represented as "x NUL" in UTF-16 (which is the format UltraEdit internally uses for Unicode), the following code works on Latin-1 as well as on Unicode files containing only Latin-1 characters.
The array
lines will contain the selected lines (or all lines of the document, if nothing was selected), ready for application of regular expressions or any other string manipulation in JavaScript:
- Code: Select all
var doc = UltraEdit.activeDocument;
if (!doc.selection.match(/\S/)) doc.selectAll(); // only whitespace selected?
var selection = UltraEdit.activeDocument.selection
.replace( /^\xEF\xBB\xBF/,"") // remove Unicode-BOM
.replace( /\x00/g,""); // poor man's transformation Latin-1-Unicode subset -> Latin-1 (not water proof, of course!)
var lineEnd = selection.match( /[\r\n]{1,2}/ ) || "\r\n" ;
var lines = selection.split( lineEnd );