Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Changes a non-ascii string into an HTML encoded ascii string.
     *
     * @param notAscii The string to change.
     *
     * @return The converted string.
     */
    public static String toAscii(String notAscii) {

        StringBuilder builder = new StringBuilder();
        char[] charArray = notAscii.toCharArray();
        for (int i = 0; i < charArray.length; ++i) {
            char a = charArray[i];
            if ((int) a > 255) {
                builder.append("&#" + (int) a + ";");
            } else {
                builder.append(a);
            }
        }
        return builder.toString();
    }
}