• (cs) in reply to dubwai

    "Doesn't .Net have any built in functionality for this type of thing?  Java has a NumberFormat class that lets you define how to parse different things like this."

    Uh, howsabout TryParse?  Did you miss the subject line???

  • (cs) in reply to Xepol
    Xepol:

    Uh, howsabout TryParse?  Did you miss the subject line???

    Sorry, I don't know TryParse from a hole in the ground.  I sincerely apologize for not being psychic.  The fuctionality in this method doesn't match up with what NumberFormat does.

  • (cs) in reply to Charles Nadolski
    Charles Nadolski:

    Hmm, this must be a feature of C# then.  In C++, char is a number between -128 and 127 (unsigned char is 0 to 255).  If you want something that will dynamically adjust to unicode or ascii depending on machine settings, you have to use the type TCHAR, _T("some text"), LPTSTR, and finally, CString.


    It's actually a .net feature (the explaination of the char datatype is from the MSDN page)... but I admit that the code is so simple it's hard to tell if it is C++ or C# (could even be C if there wasn't the public keyword)
  • (cs) in reply to dubwai
    dubwai:

    It's possible that this is desired or irrelevant but if the purpose is to determine whether the value is a simple decimal or integer, it's a bug.  I don't know what numbers "", ".", "-", or "-." are, do you?  Maybe in some strange notation that's fine but I'm guessing bug.

    I also guess "bug", but since both of us don't know the specification (if there is any), we can only guess. Would you dare to change it if you had to maintain the program and there was no indication of that function causing problems?

    dubwai:

    Doesn't .Net have any built in functionality for this type of thing?  Java has a NumberFormat class that lets you define how to parse different things like this.



    Considering this function takes a nLength parameter and accepts 0-terminated Strings (as well as the mentioned special strings "", "." "-" "-."), I think there is no direct match in eighter C# or Java. Anyway, sometimes it takes less time to re-invent a wheel than to search the libs for a suitable function, especially when the wheel takes 10 lines of code.
  • (cs) in reply to ammoQ

    ammoQ:
    Would you dare to change it if you had to maintain the program and there was no indication of that function causing problems?

    Hells no.

  • (cs) in reply to David Crosby

    One workaround, which I'm sure has been suggested already (I'm new on this block, but old elsewhere [EDSAC I]), is to allow WTF the secondary meaning of Why The Fuss?

    At least that's what I tell my 13-year-old grand-daughter, although she's big Eminem fan and knows the F-word.

    Summary: this IS a useful WTF in both senses. We have learnt some modesty and that _ignorance != _dumbth.

    skb

     

  • Friedrich (unregistered) in reply to Charles Nadolski

    "Wow that's hardcore. Kinda like building the pyramids without a level and iron tools."

    Not really... .NET and the various compilers are freely available. VS.NET isn't. So it's more like building the pyramids without forking out for slightly higher quality limestone from a neighbouring country.

  • Scott Charles (unregistered) in reply to Xepol

    Using TryParse how can you verify that the conversion was successful - if the number being converted is the number zero?

Leave a comment on “Next Time, Try TryParse”

Log In or post as a guest

Replying to comment #:

« Return to Article