Invalid ASCII character detector

Hi
As posted in this thread: http://www.opto22.com/community/showthread.php?t=304&p=945#post945 , i thought it would be a nice candidate for the competition.


//loop around and check for an invalid character in a string
//valid ASCII characters are 0-9, A-Z and a-z
//decimal character codes are: 48-57, 65-90 and 97-122 respectively

//get the string length to check
nStringLength=GetStringLength(sStringToCheck);

nInvalidCharFound=0;  //set true if we find an invalid char so we can bail asap
nIndex=0; //counter so we can loop through
nChar=0;  //character at nIndex position

repeat
  nChar=GetNthCharacter(sStringToCheck,nIndex); //get the character at index number
  IncrementVariable(nIndex);  //increment the index
  //check to see if all 3 statements are valid. if the char is not within the limits specified then its invalid.
  //add more as you see fit, even make the statics variables!!
  if (
    (not(IsWithinLimits(nChar,48,57)))  //0-9
    and
    (not(IsWithinLimits(nChar,65,90)))  //A-Z
    and
    (not(IsWithinLimits(nChar,97,122))) //a-z
    ) then 
    nInvalidCharFound=nIndex-1; //set the invalidchar variable to the position it was found
  endif
  
until ((nInvalidCharFound<>0) or (nIndex==nStringLength));  //bail if we get an invalid char found or we have reached the end of the string


does as the code says, parses a string until an invalid character is found. can be hacked to suit accordingly…

Come on iPad!!! :stuck_out_tongue:

Nick

1 Like

Passing along a small thanks from 6 years in the fuuuuutuuuuuure :slight_smile: Using this today to prevent my file names passed to my uSD card writing chart from blowing things up!

1 Like