Java ASCII from toAscii(String notAscii)

Here you can find the source of toAscii(String notAscii)

Description

Changes a non-ascii string into an HTML encoded ascii string.

License

Apache License

Parameter

Parameter Description
notAscii The string to change.

Return

The converted string.

Declaration

public static String toAscii(String notAscii) 

Method Source Code

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

public class Main {
    /**/* w w w.j  a  v  a 2s .c  om*/
     * 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();
    }
}

Related

  1. toAscii(char ch)
  2. toAscii(char source)
  3. toAscii(int i, boolean reversed)
  4. toAscii(int number)
  5. toAscii(String hexStr)
  6. toAscii(String s)
  7. toAscii(String s)
  8. toASCII(String s)
  9. toAscii(String s)