Java Hex Format formatGuidToDashedNotation(String hexValue)

Here you can find the source of formatGuidToDashedNotation(String hexValue)

Description

Returns dashed GUID notation formatted from simple hex-encoded binary.

License

Apache License

Declaration

public static String formatGuidToDashedNotation(String hexValue) 

Method Source Code

//package com.java2s;
/**//  w w w .  ja  v  a2  s. c  om
 * Copyright (c) 2016 Evolveum
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns dashed GUID notation formatted from simple hex-encoded binary.
     *
     * E.g. "2f01c06bb1d0414e9a69dd3841a13506" -> "6bc0012f-d0b1-4e41-9a69-dd3841a13506"
     */
    public static String formatGuidToDashedNotation(String hexValue) {
        if (hexValue == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(hexValue.substring(6, 8));
        sb.append(hexValue.substring(4, 6));
        sb.append(hexValue.substring(2, 4));
        sb.append(hexValue.substring(0, 2));
        sb.append('-');
        sb.append(hexValue.substring(10, 12));
        sb.append(hexValue.substring(8, 10));
        sb.append('-');
        sb.append(hexValue.substring(14, 16));
        sb.append(hexValue.substring(12, 14));
        sb.append('-');
        sb.append(hexValue.substring(16, 20));
        sb.append('-');
        sb.append(hexValue.substring(20, 32));
        return sb.toString();
    }
}

Related

  1. formatAsHexUppercase(long msgId)
  2. formatAsRawHex(int bitStringLength, String hex)
  3. formatBytes2HexString(byte[] bytes, int offset, int length)
  4. formatByteToPaddedHex(int i, int l)
  5. formatColorInt2HexString(int c)
  6. formatHEX(byte[] btValue, int iOffset, int iLength)
  7. formatHex(double theG)
  8. formatHex(int value, int width)
  9. formatHex(Integer input)