Aug
13
2009

C# equivalent to VB val() function

Although VB had it’s limitations, it was damn easy to filter an input string for a numerical value.

Here is how to do it in C#. You’ll need to use System.Text.RegularExpressions in the header

private static int VBVal(string sInput)
{
        string sOutput = string.Empty;
        MatchCollection oMatches = Regex.Matches(sInput, "\\d+");
        foreach (Match oMatch in oMatches)
        {
                sOutput += oMatch.ToString();
        }
        return (int)sOutput;
}
Written by John in: C# Tips |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment