Scannex ip.buffer User Manual
© UK 2007-2021 Scannex Electronics Ltd. All rights reserved worldwide.
15.3.4. Masking telephone digits
This complex function will mask either the last 4 numbers, or keep the first 8 only –
depending on the length of the number.
x.chnl[1].src.onrecord = function(s,c,t)
s = string.gsub(s, "%d%d%d%d%d%d%d[%d%*#]*", function(n)
local len=string.len(n)
if (len>8)
then return string.sub(n,1,8)..string.rep("X",len-8)
else return string.sub(n, 1, -5)..string.rep("X", 4)
end
end)
mem.write(c,s)
end
The gsub parameter “%d%d%d%d%d%d%d[%d%*#]*” will look for all strings that include 7
digits, followed by any number of digits, *, or # characters.
The anonymous function provided as a replacement for the string will:
Work out the length – stored in “len”
If the length is longer than 8 characters, it will keep the first 8 characters, and
substitute the remaining characters with “X”.
If the length is less than, or equal to, 8 characters then it will effectively
replace the last 4 characters with an “X”.
Obviously, any other combination is possible.
See “Programming in Lua, 2
nd
Edition”, pages 180-191 for more information on the
string.gsub function, or http://www.lua.org/pil/20.2.html and
http://www.lua.org/pil/20.3.html.
Page 125
Scannex ip.buffer User Manual
© UK 2007-2021 Scannex Electronics Ltd. All rights reserved worldwide.
15.3.4. Masking telephone digits
This complex function will mask either the last 4 numbers, or keep the first 8 only –
depending on the length of the number.
x.chnl[1].src.onrecord = function(s,c,t)
s = string.gsub(s, "%d%d%d%d%d%d%d[%d%*#]*", function(n)
local len=string.len(n)
if (len>8)
then return string.sub(n,1,8)..string.rep("X",len-8)
else return string.sub(n, 1, -5)..string.rep("X", 4)
end
end)
mem.write(c,s)
end
The gsub parameter “%d%d%d%d%d%d%d[%d%*#]*” will look for all strings that include 7
digits, followed by any number of digits, *, or # characters.
The anonymous function provided as a replacement for the string will:
Work out the length – stored in “len”
If the length is longer than 8 characters, it will keep the first 8 characters, and
substitute the remaining characters with “X”.
If the length is less than, or equal to, 8 characters then it will effectively
replace the last 4 characters with an “X”.
Obviously, any other combination is possible.
See “Programming in Lua, 2
nd
Edition”, pages 180-191 for more information on the
string.gsub function, or http://www.lua.org/pil/20.2.html and
http://www.lua.org/pil/20.3.html.
Page 125