Page 1 of 2
Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 3:55 pm
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.
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:01 pm
by skywalk
I get these in Unicode compile x86.
401
956
I get your numbers in Ascii compile mode.
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:22 pm
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?
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:29 pm
by IdeasVacuum
PB5.30 x86 WinXP
401
956
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:31 pm
by Demivec
Windows 8.1, x86 or x64 and using PureBasic v5.30.
401
956
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:37 pm
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).
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:51 pm
by luis
What the hell is happening today ?
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.
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 4:57 pm
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.
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:11 pm
by Tenaja
luis wrote:What the hell is happening today ?
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...
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:18 pm
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.
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:27 pm
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)
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:38 pm
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?
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:38 pm
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.
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:41 pm
by RASHAD
Try
File ----> File Format ----> Encoding: UTF8
Edit : LJ was first
I did not read well
Re: Asc("€") not returning unicode value
Posted: Mon Sep 15, 2014 5:45 pm
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?