i want to get only numbers from string.
Lest say that this is my string :
324ghgj123
i want to get:
324123
what i have tried:
MsgBox(Integer.Parse("324ghgj123"))
To find numbers from a given string in Python we can easily apply the isdigit() method. In Python the isdigit() method returns True if all the digit characters contain in the input string and this function extracts the digits from the string.
you can use Regex
for this
Imports System.Text.RegularExpressions
then on some part of your code
Dim x As String = "123a123&*^*&^*&^*&^ a sdsdfsdf" MsgBox(Integer.Parse(Regex.Replace(x, "[^\d]", "")))
try this:
Dim mytext As String = "123a123" Dim myChars() As Char = mytext.ToCharArray() For Each ch As Char In myChars If Char.IsDigit(ch) Then MessageBox.Show(ch) End If Next
or:
Private Shared Function Num(ByVal value As String) As Integer Dim returnVal As String = String.Empty Dim collection As MatchCollection = Regex.Matches(value, "\d+") For Each m As Match In collection returnVal += m.ToString() Next Return Convert.ToInt32(returnVal) End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With