0

In my code I am dealing with a situation whereby I have some html code that contains a list of actors are saved into a string. Some of the actor's names such as José Ferrer are appearing in the string as José Ferrer. With &#xE9 being the hexa-decimal representation of é. Does anyone have any idea of how to convert the Hex code to the character code symbol representation in C#.

Update:

I have a function that checks the names, in some cases; character such as é and presented in the string like this: "José Ferrer".

I have a function called RemovedUnicode Characters. Which aims to convert the hed code into it respective character equivalent, however I can't seem to get the function to work, this is what I have so far. The Variable Neartest just returns "&#xE9"; it does not return é.

In the code below, I isolated the unicode character reprsentation into the string called entity. By using the for loop o filter through all of the chars in the string input.

public static string RemoveUnicodeCharacterAndProduceLetter(string input) {

        StringBuilder output = new StringBuilder(input.Length);
        int endIndex;
        int startIndex;
        int length;
        string entity;

        for (int i = 0; i < input.Length; i++)
        {
            if ( input[i] == '&')
            {

                string startElement = "&";
                string endElement = ";";

                startIndex = input.IndexOf(startElement);
                endIndex = input.IndexOf(endElement, startIndex);

                length = endIndex - startIndex;

                entity = input.Substring(startIndex, length);

               //  int tempResult = Convert.ToInt16(entity);

               //  char chesse = (char)Int16.Parse(entity, NumberStyles.AllowHexSpecifier);

               string nearTest = HttpUtility.HtmlDecode(entity).ToString();

              //   string str = char.ConvertFromUtf32(Convert.ToInt32(entity));



                //
hoChay
  • 37
  • 10
  • A quick google returned multiple solutions. Such as: http://stackoverflow.com/questions/7874127/c-sharp-hexadecimal-to-char – Josh Wright Feb 14 '17 at 16:36
  • Thanks for the comments however they do not address the question – hoChay Feb 14 '17 at 16:37
  • This normally happens if the string is HTML or XML, in which case you'd be best using an HTML or XML parser. Please give more context. – Jon Skeet Feb 14 '17 at 16:39
  • 1
    In what way does that duplicate not answer the question? `return HttpUtility.HtmlDecode(input);` seems to be all you need... Also you keep missing the `;` off the end of the html entity. I'm assuming this is just a mistake on your part or is your input actually malformed in this way? – Chris Feb 14 '17 at 16:46
  • I apologise Chris, your answer was correct – hoChay Feb 14 '17 at 17:00

0 Answers0