dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
May 18, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Using the Format Function With Strings

You'll use the Format function most often with numbers, but it can be useful when applied to strings as well. For example, you can format a credit card number-which is held in a string variable, even if it contains only digits-and subdivide the number into four groups of four characters each, using a complex string expression:
 
' X holds the sequence of 16 digits
CreditCardNum = Left$(x, 4) & " " & Mid$(x, 5, 4) & " " & _
	Mid$(x, 9, 4) & " " & Right$(x, 4)
The Format function lets you accomplish the same result in a more readable and efficient way:
 
CreditCardNum = Format$(x, "!@@@@ @@@@ @@@@ @@@@")
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date