Invicore Posted April 28, 2021 Share Posted April 28, 2021 (edited) Hi I dont know why, but BinaryToString cant convert 0xB4 to string in utf8 mode I mean when I use this code to convert 0xB4 to utf8 it cant and just give me � ConsoleWrite(BinaryToString("0xB4",4) & @CRLF) but when I convert it to ascii, its convert it without any problem ConsoleWrite(BinaryToString("0xB4",1) & @CRLF) and give me " ´ " can anyone help me and tell what I'm doing wrong? thanks Edited April 28, 2021 by Invicore Link to comment Share on other sites More sharing options...
Nine Posted April 28, 2021 Share Posted April 28, 2021 (edited) 0xB4 has its MSB set to 1. So it requires at least a second byte. That char in UTF-8 is 0xC2B4 Edited April 28, 2021 by Nine Invicore 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
matwachich Posted April 28, 2021 Share Posted April 28, 2021 Dont forget to set SciTE's console to display UTF8 chars. Invicore 1 Link to comment Share on other sites More sharing options...
Invicore Posted April 28, 2021 Author Share Posted April 28, 2021 (edited) Just now, matwachich said: Dont forget to set SciTE's console to display UTF8 chars. its just for showing my problem, in full code converted string save into a txt file (utf8-bom) Just now, Nine said: 0xB4 has its MSB set to 1. So it requires at least a second byte. That char in UTF-8 is 0xC2B4 thank you, I understand, look like my only option is to only convert it as ascii, or maybe its possible to find this kind of character when using BinaryToString? can you please tell me how many character are looks like this (I mean ascii code is different then utf8), maybe I can put some exception, like $S = "" $Str = "" Do $Str &= $S $S = FileRead($File, 1) If $S == 0xB4 then $S = 0xC2B4 Until $S = 0 btw I use above code to read null-terminated strings Edited April 28, 2021 by Invicore Link to comment Share on other sites More sharing options...
Nine Posted April 28, 2021 Share Posted April 28, 2021 (edited) 13 minutes ago, Invicore said: can you please tell me how many character are looks like this As table shows above, from 0x80 to 0xFF. Here a way to convert properly a char : #include <Constants.au3> Local $cASCII = Chr(0xB4) Local $iUTF8 = StringToBinary($cASCII, 4) Local $cUTF8 = BinaryToString($iUTF8, 4) MsgBox ($MB_SYSTEMMODAL, $iUTF8, "is char " & $cUTF8 & @CRLF) Edited April 28, 2021 by Nine Invicore 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted April 28, 2021 Share Posted April 28, 2021 You can convert a whole file (single ASCII string) like this : #include <Constants.au3> Local $sASCII = "" For $i = 0x70 To 0x90 ; for an example instead of reading an ASCII file $sASCII &= Chr($i) Next Local $dUTF8 = StringToBinary($sASCII, 4) ConsoleWrite ($dUTF8 & @CRLF) Local $sUTF8 = BinaryToString($dUTF8, 4) MsgBox ($MB_SYSTEMMODAL, "Converted", $sUTF8) Invicore 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now