Author Topic: Checking to see if a string is a hex code?  (Read 471 times)

Is there any way to see if a string is a valid hex code, ie. contains only 0-9 A-F? It's not really something that bears a great deal of explanation.

RE-loving-ZOLVED.
« Last Edit: October 22, 2008, 01:36:36 PM by M »

Loop all the characters in a string and check if they are 0-9/A-F?

Sec, whipping up a small example.

-EDIT-
Ok here it is.
Code: [Select]
function checkHex(%str)
{
%cnt=strLen(%str);
for(%i=0;%i<%cnt;%i++)
{
%sub=getSubStr(%str,%i,1);
if(!isInCharList(%sub,"0 1 2 3 4 5 6 7 8 9 A B C D E F"))
{
return 0;
}
}
return 1;
}

function isInCharList(%char,%list)
{
%cnt=getWordCount(%list);
for(%i=0;%i<%cnt;%i++)
{
if(%char$=getWord(%list,%i))
{
return 1;
}
}
return 0;
}

Usage example:
Code: [Select]
checkHex("51FYD"); //returns 0
checkHex("63AF"); //returns 1
« Last Edit: October 22, 2008, 01:19:02 PM by NiXiLL »