Jump to content

Help with BinaryToString and StringToBinary, please


leuce
 Share

Recommended Posts

Hello everyone

I have text files that use "private use characters", and I would like to find all those characters and replace them with a single, known character.  As far as I can tell, the files do not use the full range of 6000 private use characters, but only ones whose codes start with "E".  This means that I can identify these characters easily by simply checking every 4th 'byte' (I'm not sure if 'byte' is the right word) to see if it is an "E", and then replacing it and the next 3 'bytes' with something else, e.g. 24EA.

I attach an image of what the two lines of text look like in two of my local text editors (since the characters won't show up correctly here in the forum).

All I need to do now is to convert "0x007B24EA24EA007D" to "{⓪⓪}", and I'll be a happy camper.  How do I do that?

#include <StringConstants.au3>

$foo = "0x007BE103E111007D"
MsgBox (0, "", $foo, 0)
MsgBox (0, "", BinaryToString ($foo, 3), 0) ; should display {}

$len = (StringLen ($foo) - 2) / 4
$position = 3

For $i = 1 to $len

If StringMid ($foo, $position, 1) = "E" Then
$foo = StringReplace ($foo, $position, "2", 1)
$foo = StringReplace ($foo, $position + 1, "4", 1)
$foo = StringReplace ($foo, $position + 2, "E", 1)
$foo = StringReplace ($foo, $position + 3, "A", 1)
EndIf

$position = $position + 4
Next

MsgBox (0, "", $foo, 0) ; should display 0x007B24EA24EA007D

; And now I need to convert $foo to {⓪⓪}, but this doesn't work:
MsgBox (0, "", StringToBinary ($foo, 3), 0)

Thanks

Samuel

(By the way, if you know of an easier/faster way to find characters of a certain code range in a text file and replace them all with a single character, I'll be happy to hear about it.)

from and to.png

Link to comment
Share on other sites

$foo = "0x007BE103E111007D"
MsgBox (0, "", $foo, 0)
$sIn = BinaryToString($foo, 3)
MsgBox (0, "", $sIn, 0) ; should display {}
$sClean = StringRegExpReplace($sIn, "[\x{E000}-\x{F8FF}]", "⓪")   ; private area range --> ⓪
MsgBox (0, "", $sClean, 0)

 

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...