Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.text.TextUtils;

public class Main {
    /**
     * Get characters' unicode in hexadecimal.
     */
    public static String getUnicode(String text, int len_limit) {
        if (TextUtils.isEmpty(text) || len_limit <= 0) {
            return "";
        }

        StringBuilder stringBuilder = new StringBuilder();

        final char[] CHARS = text.toCharArray();
        for (int len = CHARS.length, i = len - 1; i >= 0; --i) {
            if (len - i <= len_limit) {
                stringBuilder.insert(0, Integer.toHexString(CHARS[i]).toUpperCase());
                stringBuilder.insert(0, " ");
            } else {
                stringBuilder.insert(0, " ...");
                break;
            }
        }

        //Remove the first superfluous " ".
        return stringBuilder.substring(1);
    }
}