Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String representation in c#

Tags:

string

c#

im tring to grab some text from existing webpage 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 side it works for english but for languages like Hebrew it returns unrecognised chars (not an hebrew language ) is there a way to reformat the returned string ?

like image 501
aristotaly Avatar asked May 29 '26 23:05

aristotaly


1 Answers

Use the WebClient.Encoding Property to set the resource's encoding.

client.Encoding = System.Text.Encoding.UTF8;
like image 142
Jaroslav Jandek Avatar answered May 31 '26 12:05

Jaroslav Jandek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!