Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Count string length and replace each character with another

How can I count the number of characters within a string and create another string with the same number of characters but replace all of them with a single character such as "*"? Thank you.

like image 678
user Avatar asked Oct 24 '09 07:10

user


1 Answers

string newString = new string('*', oldString.Length);

Of course, it this is for displaying password equivalents, it might be better to use a fixed number of asterisks - the less clues the better. Of course, since you'd obviously be hashing the password (with salt) and storing just the hash, you couldn't know the actual length anyway ;-p

like image 197
Marc Gravell Avatar answered Nov 11 '22 15:11

Marc Gravell