string cleaning

Rob Cozens rcozens at pon.net
Mon Nov 10 19:35:40 EST 2003


>Does this look safe for Windows and Mac funny characters? Those will 
>always be > 126 ascii decimal correct?
>
>function isPrint pChar
>   set the useUnicode to false
>   get charToNum(pChar)
>   if (it < 32) or (it > 126) then return false
>   return true
>end isPrint
>
>function printableCharString pString
>  local tRes, c
>  repeat for each character c in pString
>    if isPrint(c) then put c after tRes
>  end repeat
>  return tRes
>end printableCharString
>
>

Looks OK to me, Alex; but why not just use:

function printableCharString pString
  local tRes, c
  repeat for each character c in pString
    if c < space or c > "~" then next repeat
    put c after tRes
  end repeat
  return tRes
end printableCharString

-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)


More information about the use-livecode mailing list