Mask String with characters

后端 未结 5 1605
悲哀的现实
悲哀的现实 2021-01-12 10:46

Hey guy\'s I tried to find a way to hide a string, but the code that I found just work with my application... Is there a way to hide the characters in a string with either <

5条回答
  •  长情又很酷
    2021-01-12 11:30

    Just create a string with the same number of characters as your original, with instead your "obfuscating" character.

    String x = "ABCD";
    
    String output = "";
    for (int i = 0; i < x.length(); i++) {
        output += "*";
    }
    

    Alternatively you could use x.replaceAll("\\S", "*"), which would preserve whitespace as well.

提交回复
热议问题