<<Up     Contents

Wikipedia:Unicode numeric converter script

Redirected from Unicode numeric converter script

See also this page about Unicode in general.

See below for Javascript unicode conversion thing. Works in Internet Exploiter 5.00.3502.1000


I got fed up with looking up unicode characters, so I wrote an AppleScript for my favorite styled text editor Style to write them for me. Now, I can just type Japanese into a text edit window like this

小 泉 純 一 郎

select it, choose my script from the scripts menu, and it turns into

小 泉 純 一 郎 & #23567; & #27849; & #32020; & #19968; & #37070;

Which is what you can paste into the Wikipedia edit window. I'm using a Mac, so this is a mac only solution, but I thought I'd share it for those of you who can use it. Here's the script:

____ begin script _____

set theHTML to ""
tell application "Style"
set selText to selection of document 1 as Unicode text
set selStart to get offset of selection of document 1
set selEnd to get offset of end of selection of document 1
set dataLen to (selEnd - selStart)
end tell
set tempName to "unicode temp"

tell application "Finder"
if alias tempName exists then
move alias tempName to the trash
end if
end tell

set fileRef to open for access tempName with write permission
write selText to fileRef
set myRawData to read fileRef from 0 for dataLen
close access fileRef

tell application "Finder"
move alias tempName to the trash
end tell

set numChars to dataLen div 2
repeat with n from 1 to numChars
set theHTML to theHTML & "&#"
set a to get character (2 * n - 1) of myRawData
set b to get character (2 * n) of myRawData
set lVal to ((ASCII number b) + (256 * (ASCII number a)))
set theHTML to (theHTML & lVal as string) & "; "
end repeat

tell application "Style"
set selection of document 1 to ((selection of document 1) & " ( " & theHTML & " ) ")
end tell

____end script ____

compile this in ScriptEditor, and save it in the "Style Scripts folder in the same folder where the Style application lives. I have mine saved as "Append Unicoded HTML". Thereafter it will appear in Style's Scripts menu.

Style is available at merzwaren (http://www.merzwaren.com) ($20 shareware). I have this running on Mac OS X 10.2.1 with Style version 1.9.2

Enjoy !

 Olof


Here's a Unicode to &#number; thing I wrote ages ago, can't remember why:

 <html><head><title>Unicode conversion</title><body bgcolor=#000000><font color=#ffffff><form name=a>Type here, and all characters with a code greater than 127 will be converted to &amp;#1234; codes.<br><br>Input:<br>
 <textarea name=intxt cols=80 rows=25 onKeyUp="revtxt()">Sorry, this page is useless with Javascript disabled.</textarea><br><br>Output:<br><textarea name=outxt cols=80 rows=25>Sorry, this page is useless with JavaScript disabled.</textarea><script language="Javascript">
 document.a.intxt.value="";
 document.a.outxt.value="Don't type here.";
 function revtxt(){
 var s=document.a.intxt.value;
 o="";
 for(m=0;s.charAt(m);++m)if((c=s.charCodeAt(m))<128&&c!=38) o+=s.charAt(m); else if(c==38) o+="&amp;"; else o+="&#"+c+";";
 document.a.outxt.value=o;
 }
 </script></form><br><br><br><br><br>This page written by Cyp.</font></html>

Copy to text file, rename as something.html

كسيپ Cyp 10:14 7 Jun 2003 (UTC)

wikipedia.org dumped 2003-03-17 with terodump