Asc() and Chr() for Unicode, UTF-8

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Asc() and Chr() for Unicode, UTF-8

Post by Psychophanta »

Asc() and Chr() functions for Unicode, UTF-8, and maybe also for the UTF-16
Adding the parameter [, Format] to those functions would be good.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Asc() and Chr() for Unicode, UTF-8

Post by STARGÅTE »

Chr() and Asc() already working with Unicode.

Code: Select all

Debug Asc("€")
8364

Code: Select all

Debug Chr(8364)
UTF-8 is not necessary because a string in PureBasic can exist only as ascii or unicode
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 moreTypeface - Sprite-based font include/module
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Asc() and Chr() for Unicode, UTF-8

Post by Psychophanta »

Yes ther looks like it works:

Code: Select all

For t.l=0 To 65535
  If Asc(Chr(t))<>t
    Debug "error"
  EndIf
Next
But only if compiled as unicode.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Regenduft
Enthusiast
Enthusiast
Posts: 121
Joined: Mon Mar 02, 2009 9:20 pm
Location: Germany

Re: Asc() and Chr() for Unicode, UTF-8

Post by Regenduft »

You can use PokeS() with #PB_Ascii or #PB_Unicode flag and PeekC() afterwards to get what you want. Since PokeS() also alway writes the terminating #NUL$ this works in any case.
Post Reply