Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net c# string formatting

using string format for a credit card number

发布于 2020-03-27 10:16:29

I'm trying to display a credit card number as a string like #### #### #### ####

I tried:

txtbox.Text = string.Format("{0:#### #### #### ####}", ccNumber);

and it didn't work. Any ideas?

Questioner
FiveTools
Viewed
214
dcarneiro 2011-03-28 23:21
String.Format("{0:0000 0000 0000 0000}", number)

EDIT

I paste my comment here to made it readable:

ccNumber is an Int or a string? if it's an int it should work. if it's a string you need to do a

String.Format("{0:0000 0000 0000 0000}", (Int64.Parse("1234567812345678")))