Getting the true unicode code

New to FreeBASIC? Post your questions here.
counting_pine
Site Admin
Posts: 6135
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Getting the true unicode code

Postby counting_pine » Nov 03, 2012 20:23

Hi.
Just thought I'd mention that instead of putting it inside a literal string, you could put the Wchar value directly.
It's not as convenient, but this adaptation of dkl's earlier code should work regardless of the file encoding:

Code: Select all

dim a as wstring * 32
a = wchr(8364)
print asc( a )
If the € symbol is the only one you need, perhaps this will be ok as a one-off solution.
TJF
Posts: 3421
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: Getting the true unicode code

Postby TJF » Nov 04, 2012 16:00

Morthawt wrote:Ok well I will wait and see until then, ...

When you need a prooven solution check

newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: Getting the true unicode code

Postby newbieforever » Jan 20, 2019 8:45

Wouldn't this be an answer to this old question?
Is the code correct?

Based on a hint by Josep Roca (https://www.freebasic.net/forum/viewtop ... 57#p257395).

Code: Select all

#Include once "windows.bi"
Declare Function unicd(ch As WString) As Integer

Dim As Integer      va = unicd("€")

Print va

Function unicd(ch As WString) As Integer
  DIM As WString * 2  cc = SPACE(2)
  memcpy STRPTR(cc), STRPTR(ch), 2
  Return asc(left(cc,1))
End Function
Last edited by newbieforever on Jan 20, 2019 9:37, edited 2 times in total.
Josep Roca
Posts: 414
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Getting the true unicode code

Postby Josep Roca » Jan 20, 2019 9:28

Save the file as utf-16 and you will get a correct code.

If you're going to use unicode string literals you need an editor that works with utf-16.
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: Getting the true unicode code

Postby newbieforever » Jan 20, 2019 9:41

Josep Roca wrote:Save the file as utf-16 and you will get a correct code.

I guess that's a given, yeah.

But, how can I explain to myself that your elegant but simple solution (or another one) was not presented at that time???
dodicat
Posts: 5614
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Getting the true unicode code

Postby dodicat » Jan 20, 2019 12:33

Newbieforever
Rember also that asc() is overloaded.

Code: Select all


print asc(wstr("€"))

sleep

 
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: Getting the true unicode code

Postby newbieforever » Jan 20, 2019 22:55

Finally, I understand what you mean! Thank you very much, dodicat!

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests