Asc("€") not returning unicode value

Just starting out? Need help? Post your questions and find answers here.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Asc("€") not returning unicode value

Post by Tenaja »

I am trying to write a ContainsUnicode function, but asc() is giving me small (i.e. first-byte) values, and not the expected unicode values:

Code: Select all

Debug Asc(Chr(401))	; prints: 145
Debug Asc(Chr(956))	; prints: 188
(Values chosen from the Chr() help file example.)

Yes, I have "Create Unicode Executable" selected (even tested with a CompilerIf wrapper)

Am I missing something, or is there an issue with Asc() in Unicode mode? I am using PureBasic 5.31 Beta 1 x86, in W7-64.
User avatar
skywalk
Addict
Addict
Posts: 4223
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Asc("€") not returning unicode value

Post by skywalk »

I get these in Unicode compile x86.
401
956
I get your numbers in Ascii compile mode.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Asc("€") not returning unicode value

Post by Tenaja »

I am getting 145 and 188 regardless of the string mode I compile in, both ascii and unicode, also regardless of the compiler I use, x86 or 64-bit.

What compiler & OS are you using?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Asc("€") not returning unicode value

Post by IdeasVacuum »

PB5.30 x86 WinXP
401
956
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Asc("€") not returning unicode value

Post by Demivec »

Windows 8.1, x86 or x64 and using PureBasic v5.30.

401
956
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Asc("€") not returning unicode value

Post by Tenaja »

Tenaja wrote:I am getting 145 and 188 regardless of the string mode I compile in, both ascii and unicode, also regardless of the compiler I use, x86 or 64-bit.
I just reverted back to 5.3 (from 5.31 b1), and I am still getting 145 & 188 regardless of the unicode setting or the compiler (x86 or 64).
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Asc("€") not returning unicode value

Post by luis »

What the hell is happening today ? :D

I got the same result as the others. Try a nice reboot, and then if still not working try to test everything:

Debug followed by compiler version, ascii/unicode mode, etc. and see if they really change when you change the compiler and / or its settings.
"Have you tried turning it off and on again ?"
User avatar
skywalk
Addict
Addict
Posts: 4223
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Asc("€") not returning unicode value

Post by skywalk »

Like luis said. Debug #PB_Compiler_Unicode for confirmation. Read a Unicode text file you confirmed in Notepad++ or a hex editor. Ascii compile will read ???? and Unicode compile will read correct contents.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Asc("€") not returning unicode value

Post by Tenaja »

luis wrote:What the hell is happening today ? :D

I got the same result as the others. Try a nice reboot, and then if still not working try to test everything:

Debug followed by compiler version, ascii/unicode mode, etc. and see if they really change when you change the compiler and / or its settings.
I rebooted this morning, just before starting the code.
As noted in my first post, I did wrap the test within a compilerif unicode...
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Asc("€") not returning unicode value

Post by luis »

Tenaja wrote: As noted in my first post, I did wrap the test within a compilerif unicode...
And I read it, in fact I said something different. It's yours the computer where strange things are happening.
"Have you tried turning it off and on again ?"
Little John
Addict
Addict
Posts: 4793
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Asc("€") not returning unicode value

Post by Little John »

Tenaja wrote:I am trying to write a ContainsUnicode function, but asc() is giving me small (i.e. first-byte) values, and not the expected unicode values:

Code: Select all

Debug Asc(Chr(401))	; prints: 145
Debug Asc(Chr(956))	; prints: 188
Same here (PB 5.23 LTS) if and only if in the IDE file format is set to plain text.
Better set it to Utf8. :-)
(should actually read UTF-8 BTW)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Asc("€") not returning unicode value

Post by IdeasVacuum »

I can confirm Little John's findings - if the source code file format is set to UTF8, all works as expected (401 and 956), set as plain text 145 and 188 are returned. I think I came across this before but now always have UTF8 set - think it's strange though, why should it matter?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Asc("€") not returning unicode value

Post by luis »

@LJ

Good catch !

Same here.

I don't see what the editor's file format has to do with a function which returns a number BTW.
"Have you tried turning it off and on again ?"
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Asc("€") not returning unicode value

Post by RASHAD »

Try
File ----> File Format ----> Encoding: UTF8

Edit : LJ was first :mrgreen:
I did not read well
Last edited by RASHAD on Mon Sep 15, 2014 5:48 pm, edited 1 time in total.
Egypt my love
Little John
Addict
Addict
Posts: 4793
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Asc("€") not returning unicode value

Post by Little John »

luis wrote:I don't see what the editor's file format has to do with a function which returns a number BTW.
I don't see it either.
However, I recalled that similar problems had been discussed here in the past.

Since ASCII compile mode is going to be dropped in a future PB version, maybe plain text file format should be dropped as well?
It's nothing but a remnant from the last millennium, isn't it?
Post Reply