Introduction
Regex.Replace(testnumber, "[^\d]", "")
is sufficient to remove all non-numeric characters from string testnumber
.
Using the Code
The following code was made in VB.NET. Read the numbers as string
, and assign to testnumber
. Then regular expression is applied to testnumber
, expression is "[^\d]
". Except numeric string
, rest of characters are replaced with blank.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim testnumber As String = TextBox3.Text
MessageBox.Show(System.Text.RegularExpressions.Regex.Replace(testnumber, "[^\d]", " "))
End Sub
The input is as follows:
SJHB*&8732{}\,./
The output is:
8732
History
- 1st April, 2014: Initial version