"Bullet-proof" way to get ascii string in unicode only scenary

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

"Bullet-proof" way to get ascii string in unicode only scenary

Post by Psychophanta »

"Bullet-proof" (I think) to assign an ascii string to a string variable in the 'only unicode' PB compiler versions:

Code: Select all

Macro AsignarCadenaAscii(variable,cadena,terminacion=|0)
  ;Carga una cadena de caracteres ascii extendido en una variable
  variable#=Space(Len(cadena#))
  PokeS(@variable#,cadena#,Len(cadena#),#PB_Ascii#terminacion#)
EndMacro
AsignarCadenaAscii(var$,"Hello World!")
ShowMemoryViewer(@var$,Len("Hello World!")+1)
And another one, I think also "bullet-proof":

Code: Select all

var$="Hello World!"
CopyMemory(Ascii(var$),@var$,Len(var$)+1)
ShowMemoryViewer(@var$,2*Len(var$)+1)
Last edited by Psychophanta on Mon Sep 23, 2024 6:07 pm, edited 2 times in total.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: "Bullet-proof" way to get ascii string in unicode only scenary

Post by AZJIO »

You can't use string functions to a variable, so it doesn't make sense.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: "Bullet-proof" way to get ascii string in unicode only scenary

Post by infratec »

It is really a very bad solution to overwrite a unicode string with Ascii.
You simply can't use it anymore.

You can use this:

Code: Select all

*AsciiBuffer = Ascii("Hello world")
If *AsciiBuffer
  ShowMemoryViewer(*AsciiBuffer, MemorySize(*AsciiBuffer))
  FreeMemory(*AsciiBuffer)
EndIf
which makes more sense.
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: "Bullet-proof" way to get ascii string in unicode only scenary

Post by Fred »

This is not a trick, more like a hack which isn't recommended
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: "Bullet-proof" way to get ascii string in unicode only scenary

Post by idle »

To calculate the len from an immediate unicode input string.
Len = len(input)
Len = len + (len&1)
Str.s = space(len)
Then you can poke it.

see my last post in your other thread.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: "Bullet-proof" way to get ascii string in unicode only scenary

Post by Psychophanta »

idle wrote: Tue Sep 24, 2024 11:11 pm see my last post in your other thread.
To avoid useless repeating, please watch my response in the other thread as well. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply