Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using string format for a credit card number

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?

like image 535
FiveTools Avatar asked Mar 28 '11 15:03

FiveTools


2 Answers

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")))
like image 161
dcarneiro Avatar answered Nov 15 '22 06:11

dcarneiro


You better you a masked textBox, and set the mask to:

 this.maskedTextBox1.Mask = "0000 0000 0000 0000";

or set the string format to:

 long number = 1234123412341234;
 textBox1.Text = String.Format("{0:0000 0000 0000 0000}", number);
like image 37
Mitja Bonca Avatar answered Nov 15 '22 05:11

Mitja Bonca