Here you can find the source of processUnicodeToASCII(String input)
Parameter | Description |
---|---|
input | a parameter |
public static String processUnicodeToASCII(String input)
//package com.java2s; public class Main { /**//ww w .j a v a 2s . c om * This method may no longer be necessary in Android * Anyhow, this needs some work to be more efficient * @param input * @return */ public static String processUnicodeToASCII(String input) { //String input = entrArea.getText(); String output = ""; char[] cArray = input.toCharArray(); int temp, temp1, temp3; char cTemp; int intVal = 256; String strTemp; for (int i = 0; i < cArray.length; i++) { strTemp = ""; temp = Integer.valueOf(cArray[i]); temp1 = 0; temp3 = 0; if (temp >= intVal) { temp1 = temp / intVal; if (temp1 > intVal) { temp3 = temp1 / intVal; temp1 = temp1 % intVal; if (temp3 > intVal) { temp3 = temp3 % intVal; } } strTemp += makeHex(temp); temp3 = makeInt(strTemp); output += "&#" + String.valueOf(temp3) + ";"; } else { cTemp = (char) temp; output += String.valueOf(cTemp); } } return output; } public static String makeHex(int val) { String ret = ""; String[] hexChars = new String[16]; for (int i = 0; i < 10; i++) { hexChars[i] = String.valueOf(i); } hexChars[10] = "A"; hexChars[11] = "B"; hexChars[12] = "C"; hexChars[13] = "D"; hexChars[14] = "E"; hexChars[15] = "F"; int main, remain; while (val > 0) { main = val / 16; remain = val % 16; ret = hexChars[remain] + ret; val = main; } return ret; } public static int makeInt(String hex) { int ret = 0; String[] hexChars = new String[16]; for (int i = 0; i < 10; i++) { hexChars[i] = String.valueOf(i); } hexChars[10] = "A"; hexChars[11] = "B"; hexChars[12] = "C"; hexChars[13] = "D"; hexChars[14] = "E"; hexChars[15] = "F"; int j; int k = 1; int l = hex.length() - 1; int m = hex.length() - 1; for (int i = 0; i < hex.length(); i++) { l = m - i; for (j = 0; j < hexChars.length; j++) { if (String.valueOf(hex.charAt(l)).equals(hexChars[j])) { break; } } ret += k * j; k *= 16; } return ret; } }