WriteString delivers strange 1st charakters in Data File

hangrun

New Member
Licensed User
:sign0085:Hi
I use the following code

Sub App_Start
FileOpen(c1,"data.txt",cRandom)
bin.New1(c1,False)
bin.WriteString ("This is a long text with bla bla bla")
FileClose(c1)
End Sub

The File "data.txt" shows the following result:

$This is a long text with bla bla bla

HELP! The $ should not be there !
If I write other Text, other charakters are on 1st place.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi Hangrun,

Try changing bin.New1(c1,False) to bin.New1(c1,True) and see if the fault still exists.

Regards,
RandomCoder
 

hangrun

New Member
Licensed User
solved

your comment has unfortunately not solved the issue

i solved it will following:
FilePut(c1,0,True,"WAZ WAZ is a long text with bla bla bla")

instead of the FileWrite command.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
BinaryFile.WriteString first writes the string length and then writes the actual string (this is .Net convention).
This allows you to read and write strings in arbitrary lengths.
If you like to write strings with the binary file and without this prefix you should first convert the strings to a byte array and then write the byte array.
 
Top