Jump to content

Insert Right-to-Left code in UTF-16 string?


Recommended Posts

I've been asked to write a script that will do this:

It will start with a UTF-16 text file with Arabic or Hebrew text, including line numbering, like this:

1. tfeL-to-thgiR

("tfeL-to-thgiR" represents real Right-to-Left text.)

What I want the script to do is insert a Right-To-Left code after the numeral "1" and (I think) after the "." so that the "1." will appear at the right of the text, like this:

tfeL-to-thgiR .1

Normally, numerals are coded Left-to-Right, so all Windows apps put the "1." on the left side of the text.

What I see online is that the way to fix this is put an RTL code after the number (and maybe the punctuation) in order to accomplish this. So I got the idea that I could search for this binary string:

0D 00 0A 00 31 00

and insert the RTL code after it. The internet tells me that the UTF-16 code for this mark is 20 0F.

I found a _BinaryReplace function here:

and I tried to use it this way (replacing only the line numbering "1." for simplicity):

$sInFile = "infile.txt" ; Original in file
$sFind = "0D000A003100" ; MSFT 5.0 Original hex to find
; this is rtl code: "20 0F"
$sReplace = "0D000A003100200F" ; SMASHLY! New hex to replace
$sOutFile = "outfile.txt" ; New edited out file

_BinaryReplace($sInFile, $sFind, $sReplace, $sOutFile)

But I ended up with a degree sign next to the numeral 1.

Am I missing something obvious? Thanks for any help.

 

 

Edited by emendelson
Clarification
Link to comment
Share on other sites

You can use the Unicode codepoints mentionned here:

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...