Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When parsing an element of a html document, the conversion is missing a proceeding 0

When I select an element of the html document, then convert it to an int64, its missing a preceding 0.

Using InnerHtml, I only want the last 4 characters from the "Prime Z790 BIOS 0812" result.

The result of this newz790 var should be 0812, but I just get 812.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


namespace getsqldata
{
    public static class ASUSBIOSversions
    {
        public static long newz790;
        public static async Task Run()
            
        {

            //*****************Get BIOS info from website**************
            //Scrape Website
            {
                await GethtmlAsync();
                //Console.ReadLine();
            }
            async static Task GethtmlAsync()
            {

                //Get Url for scraping and create document for parsing
                var url = "https://www.asus.com/motherboards-components/motherboards/prime/prime-z790-p/helpdesk_bios/?model2Name=PRIME-Z790-P";


                var httpClient = new HttpClient();
                var html = await httpClient.GetStringAsync(url);

                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(html);

                await Task.Delay(5000); // Add a delay of 5 seconds

                //Specify element of page to be retrieved
                var biositem = htmlDocument.DocumentNode.SelectNodes("//div[contains(@class, 'ProductSupportDriverBIOS__fileTitle')]");
                

                //Grab the BIOS version              
                ASUSBIOSversions.newz790 = Convert.ToInt64(biositem[0].InnerHtml[^4..]);
              

>Solution :

Int64 is an integer, and does not contain leading 0‘s. You can add leading zeros when casting it to a string, if you want to…

In64 Reference and using leading Zeros

If you need the zero, and grabbing it from a "string" in innerHtml, why not keep it a string?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading