What's Here?
- Members: 109,716
- Replies: 414,692
- Topics: 63,077
- Snippets: 2,289
- Tutorials: 610
- Total Online: 2,304
- Members: 74
- Guests: 2,230
Who's Online?
|
Welcome to Dream.In.Code |
|
|
Getting C# Help is Easy!
Join 109,716 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 2,304 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
This is a snippet to mimic VB6's Val() function. It will string all non-numeric characters from a string and return the numeric
|
Submitted By: PsychoCoder
|
|
Rating:

|
|
Views: 1,455 |
Language: C#
|
|
Last Modified: March 9, 2008 |
|
Instructions: Pass the method the string you want to strip. It will return only the numeric values in the provided string. You will need a reference to System.Text.RegularExpressions |
Snippet
//Namespace Reference
using System.Text.RegularExpressions;
// <summary>
/// Function to mimic the Val() function in legacy VB.
/// </summary>
/// <param name="str">String we want the numeric values from</param>
/// <returns>Integer</returns>
/// <remarks>
/// I chose to go with my own functions because there really
/// isn't an intrinsic method in C# to mimic the Val() function
///</remarks>
private static int Strip(string value)
{
string returnVal = string.Empty;
MatchCollection collection = Regex.Matches(value, "\\d+");
foreach (Match match in collection)
{
returnVal += match.ToString();
}
return (int)returnVal;
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|