Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**
     * format a string as a MAC address
     * 
     * @param address
     *            String containing at least 12 hexadecimal values
     * @return well formed MAC address
     */
    public static String prepareMACAddress(String str) {
        String address = str.replaceAll("[^a-fA-F0-9]", "").toLowerCase();
        if (address.length() < 12)
            return null;
        String[] marr = address.split("");
        address = "";
        int i;
        for (i = 1; i < 10; i = i + 2)
            address += marr[i] + marr[i + 1] + ":";
        address += marr[i] + marr[i + 1];
        return address;
    }
}