Android Question How to Convert a String that looks Like Hex to Hex or Decimal

Mahares

Expert
Licensed User
Longtime User
I have this line with 3 columns : 0xF000 glass WebApplicationIcons
B4X:
Dim CC() As Object
CC = Regex.Split(TAB, Line)

CC(0)= 0xF000 ' is retrieved from parsing the line

If I use: chr(CC(0)) I get the error: Invalid hex double:0xF000
But if I use chr(0xF000) or chr(61440) my code works.
How do I convert the string 0xF000 to hex 0xF000 or decimal 61440, so I can use chr() in Fontawesome.
Thank you
EDIT:
I removed the 0x from the string: 0xF000 and used only F000 and converted it to decimal. It worked, but I welcome better solutions and more efficient using chr().
 
Last edited:

sorex

Expert
Licensed User
Longtime User
the most common way would be

B4X:
Dim line As String="0xF000 glass WebApplicationIcons"
Dim data() As String
data=Regex.Split(" ",line)
Log( Bit.ParseInt(data(0).Replace("0x",""),16) )

not sure if that works with what you are trying to do?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
the most common way would be

@sorex:
That is precisely how I got it to work as mentioned in my edit post using the Bit.parseInt. But, I thought there might be another way with chr(data(0)).

I am still at a loss why the following code does Not work though:
B4X:
Dim strVar As String="0xF000"
  Dim Intvar As Int =strVar
Chr(Intvar) Does Not work with error: java.lang.NumberFormatException: Invalid hex double:0xF000
But if I use the value directly Chr(0xF000) instead of the variable , it works. I hope someone can give me a convincing answer.
 
Last edited:
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
@sorex:
That is precisely how I got it to work as mentioned in my edit post using the Bit.parseInt. But, I thought there might be another way with chr(data(0)).

I am still at a loss why the following code does Not work though:
B4X:
Dim strVar As String="0xF000"
  Dim Intvar As Int =strVar
Chr(Intvar) Does Not work with error: java.lang.NumberFormatException: Invalid hex double:0xF000
But if I use the value directly Chr(0xF000) instead of the variable , it works. I hope someone can give me a convincing answer.

Because Chr(0xF000) uses an integer parameter, namely 0xF000. Although it looks like a string, it is really a hex integer.
 
Upvote 0
Top