How to show only part of int in C # (e.g. cut off part of credit card number)

If I have a credit number, which is int, and I just want to display the last 4 numbers with * on the left, how would this be done in C #?

For example, 4838382023831234 will display as * 1234

+3
source share
7 answers
// assumes that ccNumber is actually a string
string hidden = "*" + ccNumber.Substring(ccNumber.Length - 4);
+11
source

If it is an integer type?

Where i am int

string maskedNumber = string.Format("*{0}", i % 10000)

This will get a module of 10,000 which will return the last four digits of int

+18
source
string myCc = myCc.ToString().Substring(12).PadLeft(1, '*');
+5

int32 , , , . , . , .

+2

.

binaryworrier: , modulo, , 1234123412340001

sshow: , (12), , 0000123412341234

:

UInt64 ccNumber;
string s = ccNumber.ToString().Text.PadLeft(15, 'myString');
string last = "*"+s.Substring(s.Length-4);

But on a more abstract note, is a credit card number really a number? I think no; it is much more likely that you will want to manipulate numbers by number than do arithmetic. Your advantage of converting char [16] to UInt64 reduces memory space by 50%. No wait 75% are stupid double-byte characters!

+2
source

If the number is stored as a string, this will do it

    string ccNumber = "4242424242424242";
    string modifiedCCNumber = "*" + ccNumber.Substring(ccNumber.Length - 4);
+1
source
string cardNo = "1234567890123456";
string maskedNo = "*" + cardNo.Substring(12,4);
+1
source

Source: https://habr.com/ru/post/1706833/


All Articles