Android Question Help to convert unicode character to Int

Juanet

Member
Licensed User
Longtime User
Hello,

I want to convert the unicode character to an integer and I do not get, surely it must be very easy but I do not know how to do it, if someone helps me I appreciate it.

That's is my code:
B4X:
Dim charToConvert As String = "0xf013"
'any of this
'Dim charToConvert As String = "f013"

Dim cs As CSBuilder
cs.Initialize
'next line works
cs.Typeface(Typeface.FONTAWESOME).Append(Chr(0xf013)).Pop
'next line not works because is a string, need conversion
cs.Typeface(Typeface.FONTAWESOME).Append(Chr(charToConvert)).Pop
 

drgottjr

Expert
Licensed User
Longtime User
to convert a hex string to an integer (and assuming the resulting value does not cause an overflow), use: Bit.ParseInt(hex,16)

there is a harder, more involved way to do it. you can google it at your leisure.

note: "0xf013" is not a hex string. "f013" is. f013 is not a hex value. 0xf013 is.
the conversion to a decimal value requires a hex string. you will get an exception if you use a hex value.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
note: "0xf013" is not a hex string. "f013" is. f013 is not a hex value. 0xf013 is.
the conversion to a decimal value requires a hex string. you will get an exception if you use a hex value.
To allow for "0x" prefix, just use replace to filter it out before passing the value to Bit.ParseInt
B4X:
cs.Typeface(Typeface.FONTAWESOME).Append(Chr(Bit.ParseInt(charToConvert.ToLowerCase.Replace("0x", ""),16))).Pop
 
Upvote 0

Juanet

Member
Licensed User
Longtime User
So basically the "magic" function is: Bit.ParseInt("hex",16)

Thank you both very much for your help, I really appreciate it.
 
Upvote 0
Top