Hi Andy,
In the 2.0 framework many Types (including primitives) now have TryParse
methods. I really don't think there is any other way to see if a string value
is of a certain format without attempting to parse it.
In earlier versions of the framework I would perform the parsing on a case by
case basis, but I can see how a simple utility may have come in handy.
Writing a utility for this is trivial, so if you find yourself parsing strings
in many different places in code then you might want to consider writing your
own.
This is the signature commonly used by the 2.0 classes, in case you're
wondering:
public static bool TryParse(string s, out [type] result)
IMO, the sig could be improved for checking whether a string can be parsed
without having to store the result in a variable. But even now it's much
nicer than having to write Try...Catch statements all over the place :)
--
Dave Sexton
"AAJ" <a.a.comwrote in message news:u9**************@TK2MSFTNGP04.phx.gbl...
Hi
has anyone come across a function to check if a particular string can be
safely converted to a datatype
i.e. i would like to check things like
TypeCheck("1/1/2006",datetime) -returns true
TypeCheck("fred",datetime) -returns false
Typecheck("100"),int32) -returns true
Typecheck("100.121"),int32) -returns false
etc....
I know I could write by own by testing within a try{} block, but I wonder if
anyone already has one already tested and working
Andy