Page 1 of 1

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

Posted: Mon Sep 23, 2024 9:23 am
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)

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

Posted: Mon Sep 23, 2024 9:38 am
by AZJIO
You can't use string functions to a variable, so it doesn't make sense.

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

Posted: Mon Sep 23, 2024 11:17 am
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.

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

Posted: Mon Sep 23, 2024 5:51 pm
by Fred
This is not a trick, more like a hack which isn't recommended

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

Posted: Tue Sep 24, 2024 11:11 pm
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.

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

Posted: Wed Sep 25, 2024 8:07 am
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. :)