finally went back after some month break, due to some personal acttacks against me in one of my old threads, even I got a simple workaround a BLitzMax bug.....
I have this code to convert UTF8 back to unicode:
I found some Visual Basic 6 (as I dosent have) native code, that can covert unicode 2 utf8, but Im are not sure how the \ 6 works in Visual Basic 6 i commented out?
Original VB6 code (under comments, not the article self) is here:
http://www.nonhostile.com/howto-convert-byte-array-utf8-string-vb6.asp
NB. Can somebody fix the spelling in the title I cant fix (covert -> convert)?
I have this code to convert UTF8 back to unicode:
Function Unicode$(UTF8$) Local RESULT$="" Local UTF$="" Local Length=0 Local Last$="" For Local i=1 To Len(UTF8$) Local Char$=Mid$(UTF8$,i,1) Local B$=Right$(Bin$(Asc(Char$)),8) If Length>0 UTF$=UTF$+Right$(B$,6) Length:-1 If Left$(B$,2)<>"10" Length=0 RESULT$=RESULT$+Last$ Last$="" ElseIf Length=0 RESULT$=RESULT$+Chr$(Bin2Int(UTF$)) EndIf EndIf If Length=0 If Left$(B$,1)="0" Result$=Result$+Char$; Length=0 ElseIf Left$(B$,3)="110" Last$=CHAR$ UTF$=Right$(B$,5) Length=1 ElseIf Left$(B$,4)="1110" UTF$=Right$(B$,5) Length=2 ElseIf Left$(B$,4)="11110" UTF$=Right$(B$,5) Length=3 EndIf EndIf Next Return RESULT$ EndFunction Function Bin2Int:Int(Binary$) Local result=0 Local D=1 For Local i=Len(Binary$) To 1 Step -1 If Mid$(Binary$,i,1)="1" Then result=result+d D=D+D Next Return result EndFunction
I found some Visual Basic 6 (as I dosent have) native code, that can covert unicode 2 utf8, but Im are not sure how the \ 6 works in Visual Basic 6 i commented out?
Function UTF8_Encode$(Value$) Local result$ For Local i = 1 To Len(value$) Local char = Asc(Mid(Value$, i, 1)) If char < 128 Result$ = Result$ + Mid(value$, i, 1) ElseIf ((char > 127) And (char < 2048)) ' Result$ = Result$ + Chr$(((char \ 64) Or 192)) Result$ = Result$ + Chr$(((char And 63) Or 128)) Else ' Result$ = Result$ + Chr$(((char \ 144) Or 234)) ' Result$ = Result$ + Chr$((((char \ 64) And 63) Or 128)) Result$ = Result$ + Chr$(((char And 63) Or 128)) EndIf Next Return result$ EndFunction
Original VB6 code (under comments, not the article self) is here:
http://www.nonhostile.com/howto-convert-byte-array-utf8-string-vb6.asp
NB. Can somebody fix the spelling in the title I cant fix (covert -> convert)?