0

I tried to make security to display email data by replacing some words with symbol (*) but not as expected there might be an error in making the example script as below.

String email = "thismyemail@myhost.com";
String get_text = email.get_text(3, 6);
String hasil = email.replace(get_text,"*");
email_string = (EditText) findViewById(R.id.emailT);
email_string.setText(hasil);

But the result is like this

thi*email@myhost.com

Which I expect

thi***email@myhost.com
irwan dwiyanto
  • 690
  • 1
  • 9
  • 28

2 Answers2

3
String hasil = email.replace(get_text,"***");

But please note that if that text appears anywhere else in the string it will be replaced as well.

Also, if the email is like jf@mymailserver.com you won't be replacing a part of their user id with *.

So you can probably find a better way to select the characters, taking into account email length and also not "replacing" text but rather putting those chars at the specific position you want to.

See this related question for some ideas on how to improve this:

masking of email address in java

eugenioy
  • 11,825
  • 28
  • 35
  • not at all, just pointing to the solution in his particular implementation, but then I added more content to the answer to point some issues – eugenioy Jul 06 '17 at 02:14
-1

Your code seems right. If ur expected output is like the one mentioned above, you can just add 2 more "*" to the code.

String hasil = email.replace(get_text,"***");

I hope it helps

Gamz Rs
  • 311
  • 5
  • 9