[英]C# - Count string length and replace each character with another
如何計算字符串中的字符數並創建具有相同字符數的另一個字符串,但用單個字符(如“*”)替換所有字符串? 謝謝。
string newString = new string('*', oldString.Length);
當然,這是用於顯示密碼等價物,使用固定數量的星號可能更好 - 線索越少越好。 當然,因為你明顯地散列密碼(鹽)和存儲剛散,你可以不知道實際長度反正;-p
另一種解決方案是:
Console.Write(System.Text.RegularExpressions.Regex.Replace("test",".", "*"));
var message = "hello world" ;
var newMessage = new String('*', message.Length);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.