string.gsub - replace ALL chars with another char i.e. *

Hi,

I am trying to replace all characters in a string to be a * because it is stroing a password…

I know I can use string.gsub but Im struggling with the ‘pattern’

I thought I had it spot on when I did this:

t = string.gsub(t, “(%a)”, “%*”) 

but it didn’t mask numbers so password1234 would become *******1234

then I tried:

t = string.gsub(t, “(%w)”, “%*”) 

which I thought worked great (again) but then it didnt mask chars such as !"£$%^&

Can anybody tell me the pattern to match absolutely any character and replace it with a *?

I know i’m close but no cigar just yet :frowning:

Many thanks

Dave

try this:

local t = “password1234”

t = string.rep( “*”, string.len(t) )

hey ojnab,

thanks for the reply!  that will certainly do the trick - cheers…

:) 

try this:

local t = “password1234”

t = string.rep( “*”, string.len(t) )

hey ojnab,

thanks for the reply!  that will certainly do the trick - cheers…

:)