unicode (no not again! :-))

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

unicode (no not again! :-))

Post by blueznl »

i am a bit baffled, as i can't seem to get to terms with unicode.. .the following should work, but it doesn't... i guess i'm missing the point somewhere...

Code: Select all

in.s = "dit is een test"
out.s = ""
;
l = WideCharToMultiByte_(#CP_OEMCP,0,@in,-1,0,0,0,0)
out = Space(l)
l = WideCharToMultiByte_(#CP_OEMCP,0,@in,-1,@out,l+1,0,0)
;
Debug l
Debug in.s
Debug out.s
in.s = out.s
;
l = MultiByteToWideChar_(#CP_OEMCP,0,@in,-1,@out,0)
out = Space(l)
l = MultiByteToWideChar_(#CP_OEMCP,0,@in,-1,@out,l)
;
Debug l
Debug in
Debug out
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Should make you more happy I guess ...

Code: Select all

;
; UNICODE strings
;
Procedure.l Ansi2Uni(ansi.s)
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0) 
  Dim unicode.w(size) 
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size) 
  ProcedureReturn @unicode()  
EndProcedure 

Procedure.s Uni2Ansi(*Unicode.l) 
  size.l = WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, #Null, #Null, #Null, #Null) 
  ansi.s=Space(size) 
  WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, @ansi, size, #Null, #Null) 
  ProcedureReturn ansi  
EndProcedure 

*pointeur=Ansi2Uni("Ben ça alors, dis donc, si j'avais su.")
Debug Uni2Ansi(*pointeur)
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

cannot store a unicode string in a normal string?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

duh... oh...

swapped the functions :-)

Code: Select all

in.s = "dit is een test"
;
l = MultiByteToWideChar_(#CP_OEMCP,0,@in,-1,0,0)
*out = AllocateMemory(l)
l = MultiByteToWideChar_(#CP_OEMCP,0,@in,-1,*out,l)
;
*in = *out
;
l = WideCharToMultiByte_(#CP_OEMCP,0,*in,-1,0,0,0,0)
out.s = Space(l)
l = WideCharToMultiByte_(#CP_OEMCP,0,*in,-1,@out,l,0,0)
;
Debug out
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

... was away for a while ! Hem it's saturday you know ... :oops:
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

blueznl wrote:cannot store a unicode string in a normal string?
can contain NULL's, so better use Memory for now
SPAMINATOR NR.1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

yeah, after some messing around i finally understood... i want my fixed length strings... oh wait, have to control my whining until fred returns :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply