Connecting Tech Pros Worldwide Forums | Help | Site Map

Format String

Newbie
 
Join Date: Nov 2009
Posts: 2
#1: 3 Weeks Ago
Hi

This is probably quite simple, but I cannot find the answer.

I have a string "000705100132" which is a Mac Address.
I would like to format it as 00:07:05:10:01:32

Thanks for your help.

Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#2: 3 Weeks Ago

re: Format String


Do you merely want to print the string in that format or do you want to create a new string? In the first case you want to use printf; in the second case you want to use sprintf.
Newbie
 
Join Date: Nov 2009
Posts: 2
#3: 3 Weeks Ago

re: Format String


I want to create a new string in the correct format.
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#4: 3 Weeks Ago

re: Format String


Verbalize what you want to do ...

First character of input string.
Second character of input string.
Colon.
Third character of input string.
...

Take a look at the "%c" format specifier for sprintf.
Reply