String replace method is not replacing characters

后端 未结 5 1102
小鲜肉
小鲜肉 2020-11-21 07:39

I have a sentence that is passed in as a string and I am doing a replace on the word \"and\" and I want to replace it with \" \". And it\'s not replacing the word \"and\" w

5条回答
  •  旧时难觅i
    2020-11-21 08:12

    package com.tulu.ds;
    
    public class EmailSecurity {
        public static void main(String[] args) {
            System.out.println(returnSecuredEmailID("sample717@gmail.com"));
        }
        private static String returnSecuredEmailID(String email){
            String str=email.substring(1, email.lastIndexOf("@")-1);
            return email.replaceAll(email.substring(1, email.lastIndexOf("@")-1),replacewith(str.length(),"*"));
        }
        private static String replacewith(int length,String replace) {
            String finalStr="";
            for(int i=0;i

提交回复
热议问题