Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello

I have string like facebook@gmail.com,i want to replace the letters after the first two alphabet with "*" till @gmail.com.
i should look like this Fa******@gmail.com.

Thanks in Advance
Posted
Comments
Tanuj Rastogi 26-Jun-14 9:33am    
Did you tried anything ?
Syed.net 26-Jun-14 15:57pm    
yup... i have marked the answer as well

Try:
C#
string input = "facebook@gmail.com";
int index = input.IndexOf('@');
string output = input;
if (index > 3)
    {
    output = input.Substring(0, 2) + new string('*', index - 2) + input.Substring(index);
    }
 
Share this answer
 
Comments
Syed.net 26-Jun-14 9:47am    
A Big thank to u ...........
OriginalGriff 26-Jun-14 10:33am    
You're welcome!
Raje_ 26-Jun-14 10:00am    
Awesome Specially for using new string('*', index - 2)
My +5.
sir, just get the index of "@" and split the first 2 char by substring and change the remaining text length by number of stars or asterisk.
 
Share this answer
 
Comments
Syed.net 26-Jun-14 9:39am    
Could plz you give an example
Its urgent
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900