Replace all characters in a string with the character '*'

advertisements

I'v searched everywhere and couldn't find an answer, if i'm wrong please direct me to the post, otherwise here's my question:

I want to replace a string (ex. "password") to all '*' but it still has the number of chars that the string has in it, for example "password" has 8 chars so it would replace it like this "********" instead of password, or any other string(ex. "word" > "****", "string" > "******").

If anyone can help me out here that would be great, thanks!


You can do something like this:

Function HideString(str As String) As String
    Return New String("*"c, str.Length)
End Function

This function creates a new string using the '*' character but with the same length as the input string.

You can use it like this:

Dim test As String = HideString("password")