add Char Entity by int for HTML - Java java.lang

Java examples for java.lang:String HTML

Description

add Char Entity by int for HTML

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        Integer aIdx = 42;//from   ww  w.  j av  a  2s.  com
        StringBuilder aBuilder = new StringBuilder();
        addCharEntity(aIdx, aBuilder);
    }

    private static void addCharEntity(Integer aIdx, StringBuilder aBuilder) {
        String padding = "";
        if (aIdx <= 9) {
            padding = "00";
        } else if (aIdx <= 99) {
            padding = "0";
        } else {
            // no prefix
        }
        String number = padding + aIdx.toString();
        aBuilder.append("&#" + number + ";");
    }
}

Related Tutorials