CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Noob

  1. #1
    Join Date
    Nov 2015
    Posts
    2

    Noob

    Okay,
    So I am new to the whole C sharp language. Two reasons I am learning this language is to build better games in Unity and the other one is to build a program at work to compare excel sheet data against data on an HTML page. My first question is, is it possible for a C Sharp program to do both of these? And while I have been learning I came up with a question that does seem rather basic to most but again, I am new to this. What is the benefit to using to.String to display a number as a string rather than just using the variable? A picture of this is below.

    Name:  1.JPG
Views: 123
Size:  12.7 KB

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Noob

    None according to the code you've written, but...

    It depends on what type the variable sum is. If it a POD type like a float, double or decimal, .ToString() offers different formatting options.

    For example, if we have a decimal value of 16325.62; and use "C" as the formatter it outputs:
    $16,325.62

    Other ToString formatter values output different formats.

    See https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    On the other hand, you can format a string using String.Format() and WriteLine has string format built in.

    So another option of formatting is to specify the format within the WriteLine method call.

    Code:
                const decimal sum = 16325.62m;
                Console.WriteLine("Sum: {0}", sum.ToString("C")); // Uses ToString to format
                Console.WriteLine("Sum: {0:C2}", sum); // Uses built-in String.Format to format
    This produces the following output:
    Sum: $16,325.62
    Sum: $16,325.62

    See https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Lastly, welcome to the site and please use the code format tags as I have done (rather than pasting a screen shot of your code or output - which makes it hard to copy and modify what you've posted).
    Last edited by Arjay; November 12th, 2015 at 05:17 PM.

  3. #3
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Noob

    It is relatively easy for a program to grab data from both Excel and HTML.

    Excel COM interop is relatively straightforward and there are many examples out there.
    Code:
    using Excel = Microsoft.Office.Interop.Excel;
    using Microsoft.Office.Core;
    The trick can be how to get the data out of the HTML, you can use XML parsing libraries
    to do this such as DOM, and attribute data will be parsed easily enough. Other types of
    data may take other kinds of trickery.
    ahoodin
    To keep the plot moving, that's why.

  4. #4
    Join Date
    Nov 2015
    Posts
    2

    Re: Noob

    Thanks for the replies guys. It's much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured