Hi i am working with a webservice in android where I am receiving an array of strings i used this to convert the webservice response to utf-8
InputStreamReader isr = new InputStreamReader(
httpConn.getInputStream(), Charset.forName("UTF-8"));
then I am using DocumentBuilderFactory to parse the xml and get all the data with a for my problem is that in the database there are some data in ISO-8859-1 and other with UTF-8 i use this function to remove the accent
for (int i = 0; i < nList.getLength(); i++) {
for (int x = 0; x < list; x++) {
Node a = nInterna.item(x);
if (a.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) a;
nidprod = element.getElementsByTagName("ccidclie");
line = (Element) nidprod.item(0);
temp = getCharacterDataFromElement(line);
id[x] = df.format(Float.parseFloat(temp));
nidprod = element.getElementsByTagName("ccname");
line = (Element) nidprod.item(0);
temp = getCharacterDataFromElement(line);
name[x] = deleteAccept(temp.toString().toUpperCase());
}
}
}
public static String deleteAccept(String string) {
String newstring = Normalizer.normalize(string, Normalizer.Form.NFD)
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
return newstring;
}
but is not working with iso-8859-1 then i try this way
String deleteAccept(String string) throws UnsupportedEncodingException {
return new String(string.getBytes("UTF-8"), "ISO-8859-1");
}
to cover the two cases but it is not working fine, my question is how can i replace the character that is encode with utf-8 and the character that is encode with iso-8859-1 thanks to all that can help me with an advice.
No comments:
Post a Comment