Android Question String length

gruizelgruis

Member
Licensed User
Longtime User
Hi all,
Sorry if this has been asked before.
I'm debugging a project I created a view years back. I think I run into a string length problem. My question is:
What is the max lengts of a variabel declared as a string ?
Are there any alternatives ?

Pls advice
 

OliverA

Expert
Licensed User
Longtime User
I did. It worked. But .... is ..... very .... slow .....
In Release mode?

Im not getting anywhere with this. am I correct to say if the length of the string is Len(senddata) = 603 Then the prefix would be chr(93) & chr(2) & chr(0) & chr(0) ?
please advice I'm lost
Looking at the code I linked to in post #18, as long as Len(senddata) returns a Int32 value, you should just Write(Len(senddata)).

Code snippet from linked code:
B4X:
Dim name As Byte() = Encoding.UTF8.GetBytes(Path.GetFileName(fileToSend))
Dim bw As New BinaryWriter(stream)
'send the first message which is the file name
bw.Write(name.Length)
bw.Write(name)
Instead of a filename, you just need to sent your UTF8 encoded string, so something like
B4X:
Dim myTextToSent = "Some really really long string here"
Dim data As Byte() = Encoding.UTF8.GetBytes(myTextToSent)
Dim bw As New BinaryWriter(stream)
'send the first message which is the file name
bw.Write(data.Length)
bw.Write(data)
Note: This is just a code snippet. You still need to set up the "stream" variable/object. I'm not a VB6 programmer, I'm just going by the code provided (linked to in post#18).
 
Upvote 0

gruizelgruis

Member
Licensed User
Longtime User
Why aren't you using AsyncStreamsText ? You just need to make sure that each message ends with an end of line character.
I did try asyncstreamstext, It was very slow compared to asyncstreams. Atleast in design mode it was.
I use asyncstreams with prefix now. And it looks good. I'll be testing it this weekend.

@OliverA Thank you for your input. I managed the 4byte the prefix with this code

B4X:
Public Function LongToByte(ByVal lng As Long) As String
Dim Rest As Byte
Rest = lng \ 255
LongToByte = Chr((lng - (255 * Rest)) - Rest) & Chr(Rest) & Chr(0) & Chr(0)
end function
Its good enough for string lengths upto 65025. I'm sending the sendata just as tekst.
 
Last edited:
Upvote 0
Top