Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to convert middle 4 credit card no to xxxx in c#?
Posted
Updated 12-Jan-14 19:28pm
v2
Comments
What have you tried and where is the problem?

Try this:

C#
string carditCardNumber = "4477468697203003";
            int halfPoint = carditCardNumber.Length / 2;
            string carditCard = carditCardNumber.Substring((halfPoint - 2), 4);
            string updateCarditCardNumber = carditCardNumber.Replace(carditCard, "xxxx");
            Response.Write(updateCarditCardNumber);
 
Share this answer
 
Try this..


C#
string creditcardno = "1234567891011125";
        List<char> temp = creditcardno.ToList();

        int which4ToBeMadeasXXX = 4;
        int end = (which4ToBeMadeasXXX) * 4;
        int start = end - 4;

        for (int i = start; i < end; i++)
            temp[i] = 'X';


        creditcardno = string.Join("", temp);
 
Share this answer
 
Comments
Member 10276220 13-Jan-14 1:37am    
thnx karthik...if i want this in source page...then what will be the code?
please help...i wanna show this no in gridview
Karthik_Mahalingam 13-Jan-14 1:49am    
post your full code, i will help you...
Member 10276220 13-Jan-14 1:56am    
i have a grid view...i wanna show credit card no in this gridview like "123456789XXXX123"
how to do this in source page??
Karthik_Mahalingam 13-Jan-14 2:01am    
ok fine..
pls post your code, what you have tried
then i can modify the same..
Karthik_Mahalingam 13-Jan-14 2:04am    
wait for sometime.. going to break, wil be back in 20 mins

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