Android Question bc.StringToBytes irritation [solved]

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
bytearray 1 longer then text - what can be the reason? the FORELAST byte (13:-62 -62 ffffffc2 ᅡ) seems to be inserted...

if last byte < 0x80, then result seems to be correct. does "utf8" make adaptiones? what is the alternative?

... ok, Dim b2() As Byte = bc.StringToBytes(text,"ASCII") works well :)

B4X:
    Dim Header As String = "MThd" & Chr(0x00) & Chr(0x00) & Chr(0x00) & Chr(0x06) & Chr(0x00) & Chr(0x00) & Chr(0x00) & Chr(0x01)  & Chr(0x01)   & Chr(0x80)' 4D 54 68 64 00 00 00 06 ff ff nn nn dd dd
   tron(Header)

private Sub tron(text As String)
 
    Dim myLen As Int = text.length
    Dim b2() As Byte = bc.StringToBytes(text,"utf8")
    Log("tron----------------------------")
    Log("txtLength: " & myLen)
    myLen = b2.Length
    Log("byteLength: " & myLen)
    For i = 0 To b2.Length - 1
        Try
            Dim myInt As Int = b2(i)
            Log(i & ":" & b2(i) & " " & myInt & " " & Bit.ToHexString(myInt) & " " & Chr(myInt))
        Catch
            Log(LastException)
        End Try

    Next
End Sub


tron----------------------------
txtLength: 14
byteLength: 15
0:77 77 4d M
1:84 84 54 T
2:104 104 68 h
3:100 100 64 d
4:0 0 0 ��
5:0 0 0 ��
6:0 0 0 ��
7:6 6 6
8:0 0 0 ��
9:0 0 0 ��
10:0 0 0 ��
11:1 1 1
12:1 1 1
13:-62 -62 ffffffc2 ᅡ
14:-128 -128 ffffff80 タ
 
Last edited:

hatzisn

Well-Known Member
Licensed User
Longtime User
Why don't you just use f.e. "sometext".Getbytes... etc. If you are trying to send a string in your mother language then use the stringutils and encode URL from one side and decode URL on the other...
 
Upvote 0
Top