Trim everything BUT numbers from a string.

what is the best way to trim all characters and special characters like ( ) from a string leaving JUST the numbers.

So the string would look like:

323 (NoNote)

So I would want to trim , letters, special characters and spaces.

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

       Dim a, b As String
        a = "123 % Hello $ 456 world 789 $"

        '  b = "12345678"
        b = System.Text.RegularExpressions.Regex.Replace(a, "[^\d]", "")
        b = System.Text.RegularExpressions.Regex.Replace(b, "\s+", " ")

Imports System.Text.RegularExpressions
Imports System.Text

Public Function GetOnlyNumbers(Value As String) As String
  Dim sb As New StringBuilder

  For Each match As Match in RegEx(Value, "\d")
  Next match
  Return sb.ToString()
End Function

?GetOnlyNumbers("adg3234 asdfafd sadf4355")

Instead of using RegEx, you can simply iterate through the characters of the string and check each one:

    Public Function GetOnlyNumbers(ByVal sValue As String) As String
        Dim sb As New StringBuilder
        For Each c As Char In sValue
            If Char.IsDigit(c) Then sb.Append(c)
        Next c
        Return sb.ToString
    End Function
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Bob LearnedCommented:
Simple way:

Dim number As Double = Val(text)

Hello cjinsocal581,
       The best way to do it by this :

         Dim str as string = "aabb2ukjh456lkjfc87y345"
dim finalstr as string = string.empty

      For i = 1 To lstr.Length
            strchar = Mid(line, i, 1)
               if isnumeric(strchar) then
                  finalstr & = strchar
               end if
         end try            
     Next i

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.