iOS Question IsNumber to work on hexstrings?

techknight

Well-Known Member
Licensed User
Is there a way to test hexstrings to see if its a valid hex value?

For example my packet always comes in as a hex string. it has "123CXXXXX" 3C being the length.

Problem is, if for some odd reason my Socket gets something other than a hex string, it crashes because well, 3C isnt a length, its whatever the text is. Such as any combination of letters and numbers.

Is there a way to test that the string has all valid hexadecimal letters/numbers?
 

omidaghakhani1368

Well-Known Member
Licensed User
Hello my friend
I suggest use regex.
B4X:
Log(Regex.IsMatch("^(0x|0X)?[a-fA-F0-9]+$",yourhexstring))
yourhexstring is hex number
If match return true
 

techknight

Well-Known Member
Licensed User
Ah. Still from the VB6 world so I didnt know anything about a Regex.

Plus what do all the random characters you have listed mean? I am sure they arnt random, but I see alot of extras that I dont know what they are doing there?
 

omidaghakhani1368

Well-Known Member
Licensed User
Oh my god,Regex is sweetest topic in programming world.
Regex is complete and without any problem and too complex
 

techknight

Well-Known Member
Licensed User
Well I dont program in any other language except BASIC, and regex doesnt really exist in BASIC except for maybe this. And I came from VB6 and it doesnt have Regex
 

omidaghakhani1368

Well-Known Member
Licensed User
Regex exist in all programming language
Regex in basic is easy.
Use my example code in above post
 
Top