Re: Ascii-Strings in Data
Posted: Thu Mar 23, 2017 5:29 pm
Cool, I should have caught the long also. 

http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Debug PeekS(?HelloAscii, -1, #PB_Ascii)
Debug PeekS(?HelloUnicode, -1, #PB_Unicode)
Debug PeekS(?HelloUTF8, -1, #PB_UTF8)
DataSection
HelloAscii:
Data.p-ascii "Hello Ascii!"
HelloUnicode:
Data.p-unicode "Hello Unicode!"
HelloUTF8:
Data.p-utf8 "Hello UTF8!"
EndDataSection
Code: Select all
Structure Scan
i.i[0]
EndStructure
DataSection
IsAscii:
Data.a "Ascii 1", "Ascii 2", "Ascii 3"
IsUnicode:
Data.c "Unicode 1", "Unicode 2"
IsUTF8:
Data.a "UTF8 1", "UTF8 2"
EndDataSection
ShowMemoryViewer(?IsAscii, 32)
Define.s s$
Define *scan.Scan = ?IsAscii
Debug "--Using PeekS(*scan)--"
Debug PeekS(*scan, -1, #PB_Ascii) ; OK
Debug PeekS(*scan+Len("Ascii 1")+1, -1, #PB_Ascii) ; OK
Debug PeekS(*scan+Len("Ascii 1")+1+Len("Ascii 2")+1, -1, #PB_Ascii) ; OK
;Debug PeekS(*scan\i[0], -1, #PB_Ascii) ;<-- IMA?
Restore IsUnicode
Read.s s$
Debug "--Using Read.s--"
Debug s$
Debug "--Using PeekS(label)--"
Debug PeekS(?IsAscii, -1, #PB_Ascii)
Debug PeekS(?IsUnicode, -1, #PB_Unicode)
Debug PeekS(?IsUTF8, -1, #PB_UTF8)
Code: Select all
Define a.s
Macro _ReadAscii( MemoryAddress, VarName)
Read.s VarName
MemoryAddress = Ascii(VarName)
VarName = PeekS(MemoryAddress, Len(VarName), #PB_Ascii)
EndMacro
Restore ty
For i = 1 To 4
_ReadAscii( buffer.i, myinfo.s)
Debug myinfo
ShowMemoryViewer(buffer, Len(myinfo))
Delay(1500)
Next
DataSection
ty:
Data.s "Hello World !"
Data.s "This is my "
Data.s "little macro"
Data.s "Effort!!!!"
EndDataSection
Code: Select all
DataSection
HelloUnicode:
Data.p-unicode "Ћирилица"
HelloUTF8:
Data.p-utf8 "Ћирилица"
EndDataSection
Code: Select all
DataSection
HelloUnicode:
Data.b $0B, $04, $38, $04, $40, $04, $38, $04, $3B, $04, $38, $04, $46, $04, $30, $04, $00, $00
HelloUTF8:
Data.b $D0, $8B, $D0, $B8, $D1, $80, $D0, $B8, $D0, $BB, $D0, $B8, $D1, $86, $D0, $B0, $00
EndDataSection
Code: Select all
DataSection
IsUnicodeC:
Data.c "Ћирилица", "Ћирилица2", "Ћирилица3"
IsUnicodeS:
Data.s "Ћирилица", "Ћирилица2", "Ћирилица3"
EndDataSection
ShowMemoryViewer(?IsUnicodeS, 64)
Restore IsUnicodeS
Read.s s$
Debug "--Using Read.s--"
Debug s$
Restore IsUnicodeC
Read.s s$
Debug "--Using Read.s--"
Debug s$
Debug "--Using PeekS(label)--"
Debug PeekS(?IsUnicodeC, -1, #PB_Unicode)
Debug PeekS(?IsUnicodeS, -1, #PB_Unicode)
Code: Select all
DataSection
AsciiData:
Data.a "Hello!" : Data.a #NUL
UnicodeData:
Data.u "Hello!" : Data.u #NUL
EndDataSection
Debug PeekS(?AsciiData, -1, #PB_Ascii)
Debug PeekS(?UnicodeData, -1, #PB_Unicode)