开发者

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

开发者 https://www.devze.com 2022-12-09 02:50 出处:网络
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 \"*\"?Tha

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.


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


var message = "hello world" ;
var newMessage = new String('*', message.Length);


Another solution would be:

Console.Write(System.Text.RegularExpressions.Regex.Replace("test",".", "*"));
0

精彩评论

暂无评论...
验证码 换一张
取 消