Java how can I add an accented "e" to a string?

Posted by behrk2 on Stack Overflow See other posts from Stack Overflow or by behrk2
Published on 2010-04-18T04:19:47Z Indexed on 2010/04/18 4:23 UTC
Read the original article Hit count: 567

Filed under:
|
|
|
|

Hello,

With the help of tucuxi from the existing post Java remove HTML from String without regular expressions I have built a method that will parse out any basic HTML tags from a string. Sometimes, however, the original string contains html hexadecimal characters like é (which is an accented e). I have started to add functionality which will translate these escaped characters into real characters.

You're probably asking: Why not use regular expressions? Or a third party library? Unfortunately I cannot, as I am developing on a BlackBerry platform which does not support regular expressions and I have never been able to successfully add a third party library to my project.

So, I have gotten to the point where any é is replaced with "e". My question now is, how do I add an actual 'accented e' to a string?

Here is my code:

public static String removeHTML(String synopsis) {

char[] cs = synopsis.toCharArray();
  String sb = new String();
  boolean tag = false;
  for (int i = 0; i < cs.length; i++) {
   switch (cs[i]) {
   case '<':
    if (!tag) {
     tag = true;
     break;
    }
   case '>':
    if (tag) {
     tag = false;
     break;
    }
   case '&':

    char[] copyTo = new char[7];
    System.arraycopy(cs, i, copyTo, 0, 7);

    String result = new String(copyTo);

    if (result.equals("&#x00E9")) {
     sb += "e";
    }

    i += 7;
    break;
   default:
    if (!tag)
     sb += cs[i];
   }
  }

  return sb.toString();
 }

Thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about accents