Is there an easy way to do this string conversion?
I have found Ascii() and UTF8() but not something to go the other way.
Convert a #PB_Ascii or #PB_UTF8 string to UCS2
Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
UCS2 is from 0 to $FFFF equal to UTF-16 which is used by PB internally.
There is no need for UCS2() because you can simply use the pointer to the unicode-string "@string"
There is no need for UCS2() because you can simply use the pointer to the unicode-string "@string"
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
PokeS() using #PB_Unicode.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
Thank you, that made things very straightforward.skywalk wrote:PokeS() using #PB_Unicode.
Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
Code: Select all
;-TOP by mk-soft
CompilerIf #PB_Compiler_Version < 550
Procedure Ascii(String.s)
Protected *memory
*memory = AllocateMemory(StringByteLength(String, #PB_Ascii) + 1)
If *memory
PokeS(*memory, String, -1, #PB_Ascii)
EndIf
ProcedureReturn *memory
EndProcedure
Procedure UTF8(String.s)
Protected *memory
*memory = AllocateMemory(StringByteLength(String, #PB_UTF8) + 1)
If *memory
PokeS(*memory, String, -1, #PB_UTF8)
EndIf
ProcedureReturn *memory
EndProcedure
CompilerEndIf
Procedure Unicode(String.s)
Protected *memory
*memory = AllocateMemory(StringByteLength(String, #PB_Unicode) + 2)
If *memory
PokeS(*memory, String, -1, #PB_Unicode)
EndIf
ProcedureReturn *memory
EndProcedure
;-;(
text.s = "Hello World!"
*mem = Unicode(text)
Debug PeekS(*mem)
FreeMemory(*mem)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive