You could run for conversion several case-sensitive replaces searching (in worst case 128 times) a single ANSI character with a byte value greater than 127 to appropriate UTF-8 byte sequence. But for existing UTF-8 files that would damage the character encodings.
So it would be better to this with a macro as posted at
Convert multiple files to UTF-8.
But nowadays with
UltraEdit for Windows ≥ v17.30 or UEStudio ≥ v11.20 it is even better to use a script for this task.
Edited on 2013-12-05:
After most script code was already available public for this task and some script newbies needed additional help on putting my script code snippets together to a working script for this task, I have decided to write a complete, full featured script for conversion of text files to UTF-8 and publish it.
On
Macros & Scripts download page there is
Convert files to UTF-8 with a link to the script file
ConvertFilesToUtf8.js which was last updated on 2018-11-14.
This script file can be downloaded, opened in UltraEdit or UEStudio and executed with clicking in menu
Scripting on menu item
Run active script on using toolbar/menu with traditional menus, or clicking on ribbon tab
Advanced in group
Script on item
Play script on using ribbon mode.
Attention: Users of a non English version of UltraEdit/UEStudio must first edit the two strings of
sSummaryInfo and
sResultsDocTitle in the script as explained in the comments of the script.
The script user is asked if the script should be executed on files in a directory or a list of files like all open files or all project files.
If the choice is taken for running the script on all files of a directory, the script user has to enter the path to the directory, the file type specification which can contain wildcards and allows multiple strings separated by semicolons, and if all matching files in all subdirectories of the specified directory should be processed, too.
The script creates now first a list of files to process. Note: Files with Unicode characters in name are not supported!
Then the script processes each file in the list with writing information about the activities into the output window.
Finally the script writes into the output window how many files have been processed in total, how many files have been converted to UTF-8, how many files were not modified because already being a Unicode file (encoded in UTF-8) and how many files were skipped because of being a binary file.
The script additionally searches in all files converted to UTF-8 for a character set declaration as present usually in head section of an HTML or XHTML file and for an encoding declaration as usually present in first line of an XML file and modifies those declarations also to UTF-8 to match the used encoding. The summary in output window contains also the information how many character set and how many encoding declarations were additionally modified.
Special hint:
If the script should be used to run on all open files, it is better to add the script file via
Scripting - Scripts (traditional menus) or
Advanced - All scripts (contemporary menus or ribbon mode) to the list of scripts and run it from the menu
Scripting (traditional menus) or the
Script List window opened with
View - Views/lists - Script list (traditional menus) or
Layout - Script list (contemporary menus or ribbon mode) or instead of opening the script file in UE/UES and run it with command
Run active script (Alt+Shift+R).
The script has no code to skip itself on conversion to UTF-8. Therefore the script would on execution convert itself to UTF-8. Usually that does not really matter as
ConvertFilesToUtf8.js does not contain any character with a code value greater 127 as long as a localization of the 2 strings does not result in adding ANSI characters. Therefore the conversion to UTF-8 changes nothing on byte content of the script file. So the script remains an ASCII file as required for the JavaScript interpreter. But that is only true if UE/UES is configured to not write a byte order marker (BOM) on saving UTF-8 encoded files, see the comments of the scripts for details about BOM behavior.
If a UTF-8 BOM is added by mistake to
ConvertFilesToUtf8.js, the JavaScript interpreter would output a syntax error on execution into the output window which is in this case not automatically opened.
The line and block comments can be removed from script file by running a replace all (from top of file) searching with
Perl regular expression for
^ *//.+[\r\n]+|^ */\*[\s\S]+?\*/[\r\n]+| +//.+$ and using an empty replace string. The
first part in this
OR expression with three arguments matches
entire lines containing only a line comment, the
second part matches
block comments, and
third part matches
line comments right to code. Removal of the comments makes the usage of this script more efficient on using it often because of JavaScript interpreter has to interpret less characters and lines.