A new Unicode & Newbie problem

New to FreeBASIC? Post your questions here.
Posts: 117
Joined: Jun 21, 2018 11:14

Re: A new Unicode & Newbie problem

Postby newbieforever » Jan 19, 2019 1:26

Wow...wow...wow!!! What magic wand is this now?! And it really works!!!

And you, Josep, are the magician! Thank you very much!!!

(Btw: What a strange dynamic this thread had! At first everything was unclear and it seemed that there was no solution. But then, by my naive questioning (and by my small rather random discovery to the variable won by LoadFile()) you decided to reach deep into your magic box! Or did you already know before that the solution goes in this direction?)

(Btw 2: I was extremely confused because I saw that the 2-byte code of the two "e" in "Сергeй" was not identical, and initially thought the method was not working properly. Only after a while did I realize: I copied "Сергeй" from somewhere, and the original writer typed two different "e", a Cyrillic one and a Latin one––both look the same.)
Posts: 5693
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: A new Unicode & Newbie problem

Postby dodicat » Jan 19, 2019 15:00

I tried a union with this.

Code: Select all

const size=1000

type ub
 as ubyte b(1 to size*2)
end type
union wsize
as wstring * size w
as ub b
end union

function getstring(z as wsize) as string
dim as string g
for n as long=1 to size*2
next n
return g
end function

#Include "file.bi"

Sub savefile(filename As String,p As string)
    Dim As Integer n
    If Open (filename For Binary Access Write As #n)=0 Then
        Put #n,,p
        Print "Unable to save " + filename
    End If
End Sub

Function loadfile(file as string) as wString ptr
   If FileExists(file)=0 Then Print file;" not found":Sleep:end
   var  f=freefile
    Open file For Binary Access Read As #f
    static As wString * size text
    If Lof(f) > 0 Then
      text = String(Lof(f), 0)
      Get #f, , text
    End If
    Close #f
    return @text
end Function

dim as wsize x
dim as wstring * size w= "Сергeй"

for n as long=1 to 7
w+=chr(10)+" Please close notepad if it is showing"
print "The wstring:"
print w

print "text to save to file:"
print getstring(x)


shell "notepad tester.txt"
print "retrieve from file"
dim as wstring ptr  wp=loadfile("tester.txt")
print *wp

'kill "tester.txt"


I had to use the Poseidon Ide to handle unicode.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest