It is currently Mon Apr 12, 2021 3:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
PostPosted: Thu Apr 08, 2021 9:09 pm 
Offline
New User
New User

Joined: Sun Sep 23, 2018 3:18 am
Posts: 6
Is there an easy way to do this string conversion?

I have found Ascii() and UTF8() but not something to go the other way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
PostPosted: Thu Apr 08, 2021 9:13 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1429
Location: Germany, Glienicke
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"

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
PostPosted: Thu Apr 08, 2021 9:16 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3460
Location: Boston, MA
PokeS() using #PB_Unicode.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
PostPosted: Fri Apr 09, 2021 1:00 am 
Offline
New User
New User

Joined: Sun Sep 23, 2018 3:18 am
Posts: 6
skywalk wrote:
PokeS() using #PB_Unicode.


Thank you, that made things very straightforward.


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert a #PB_Ascii or #PB_UTF8 string to UCS2
PostPosted: Fri Apr 09, 2021 8:33 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2943
Location: Germany
Code:
;-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 / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye