Click here to Skip to main content
15,914,071 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i have a string abcd 36.2 How to get the value 36.2 only , with abcd can be changed?
Posted

Hi dec82;

you could use a regular expression to pull the numeric data out.

<br />        ' Test data<br />        Dim testData As String = "abcd 36.2"<br />        ' String to hold the wanted info<br />        Dim numericValue As String = String.Empty<br />        ' A regular Expression to pull out the needed info<br />        Dim m As Match = Regex.Match(testData, "^.*?(\d+(?:\.\d+)?)")<br />        ' Test to see if the string had a numeric value on the end of it<br />        If m.Success Then<br />            ' Pull out the information<br />            numericValue = m.Groups(1).Value<br />        End If<br /><br />        MessageBox.Show("Numeric Value = " & numericValue)<br />


Fernando
 
Share this answer
 
Hi
one option is that you can loop through the entire string and check for numerics
ie.

Dim x As String = "abcd 36.2"<br />            Dim value As String = ""<br />            For lp As Integer = 0 To x.Length - 1<br />                If IsNumeric(x.Chars(lp)) Or x.Chars(lp) = "." Then<br />                    value &= x.Chars(lp)<br />                End If<br />                Application.DoEvents()<br />            Next<br />            MsgBox(value)


hope this helps
Anoop
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900