C#, Pulling only numeric values from a string

Posted on 2007-10-01
Last Modified: 2013-12-17
I am trying to pull only the number values from a string.  They will always start with a string and end in a numbers.

i.e ABC213
I only want to get the 213.

Question by:vandy02
    LVL 58

    Accepted Solution

    yourNumericString = System.Text.RegularExpressions.Regex.Replace(yourString, "[^0-9]", "");
    LVL 8

    Expert Comment

    This will give you the numbers in a string, use Double.Parse or Int.Parse to convert this string into a double/int.
    LVL 58

    Expert Comment

    Regex.Replace would do what was asked. So I would recommend a PAQ.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    network + 7 60 euclidean math 2 26
    C# Winform panel within a panel 4 33
    Best charting add on for .Net Applications 2 20
    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now