Advertisement
Guest User

Grokking 239

a guest
Nov 2nd, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. class Solution {
  2.     public String maskPII(String S) {
  3.         String s = S.toLowerCase();
  4.         if (s.contains("@")) {
  5.             int index = s.indexOf("@");
  6.             String str = s.substring(0,index);
  7.             return str.substring(0, 1)
  8.                 + "*****" + str.substring(str.length() - 1, str.length())
  9.                 + s.substring(index);
  10.         } else {
  11.             s = s.replace("+", "");
  12.             s = s.replace("-", "");
  13.             s = s.replace("(", "");
  14.             s = s.replace(")", "");
  15.             s = s.replace(" ", "");
  16.             if (s.length() == 10)
  17.                 return "***-***-" + s.substring(6);
  18.             else if(s.length() == 11)
  19.                 return "+*-***-***-" + s.substring(7);
  20.             else if(s.length() == 12)
  21.                 return "+**-***-***-" + s.substring(8);
  22.             else
  23.                 return "+***-***-***-" + s.substring(9);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement