String representation in C #

im tring to grab some text from an existing web page using this method:

  try
        {

            WebClient client = new WebClient();
            result = client.DownloadString(url);
            int start = result.IndexOf("startpointstr") ;

            end = result.IndexOf("EndpointStr");

            result = result.Substring(start, end - start);
          string.Format(
            MessageBox.Show(result);


        }
        catch (Exception ex)
        {
            // handle error
             MessageBox.Show(ex.Message);

        }

in the positive part, it works for English but for languages ​​like Hebrew it returns unrecognized characters (and not Hebrew) is there a way to reformat the returned string?

+3
source share
2 answers

Use the WebClient.Encoding property to set the encoding of resources.

client.Encoding = System.Text.Encoding.UTF8;
+5
source

You will need to know the encoding of the loaded page before converting it to a string. Some candidates for review will be in order of priority:

  • HTTP content type of response (value of the charset attribute)
  • http-equiv META tag (charset attribute value)
  • ( )
  • UTF-8

, - UTF-8, .

+1

All Articles