Get a string of number ?
-
Hi one option is that you can loop through the entire string and check for numerics ie.
Dim x As String = "abcd 36.2"
Dim value As String = ""
For lp As Integer = 0 To x.Length - 1
If IsNumeric(x.Chars(lp)) Or x.Chars(lp) = "." Then
value &= x.Chars(lp)
End If
Application.DoEvents()
Next
MsgBox(value)hope this helps Anoop
-
-
Hi one option is that you can loop through the entire string and check for numerics ie.
Dim x As String = "abcd 36.2"
Dim value As String = ""
For lp As Integer = 0 To x.Length - 1
If IsNumeric(x.Chars(lp)) Or x.Chars(lp) = "." Then
value &= x.Chars(lp)
End If
Application.DoEvents()
Next
MsgBox(value)hope this helps Anoop
That's the hard, slow, and non-globalized way to do it...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hi one option is that you can loop through the entire string and check for numerics ie.
Dim x As String = "abcd 36.2"
Dim value As String = ""
For lp As Integer = 0 To x.Length - 1
If IsNumeric(x.Chars(lp)) Or x.Chars(lp) = "." Then
value &= x.Chars(lp)
End If
Application.DoEvents()
Next
MsgBox(value)hope this helps Anoop
-
Is the format always going to be 'AAAA ##.##'? Meaning is the value always going to be 4 letters followed by a space?
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
Hi dec82; you could use a regular expression to pull the numeric data out.
' Test data Dim testData As String = "abcd 36.2" ' String to hold the wanted info Dim numericValue As String = String.Empty ' A regular Expression to pull out the needed info Dim m As Match = Regex.Match(testData, "^.\*?(\\d+(?:\\.\\d+)?)") ' Test to see if the string had a numeric value on the end of it If m.Success Then ' Pull out the information numericValue = m.Groups(1).Value End If MessageBox.Show("Numeric Value = " & numericValue)
Fernando
-
Is the format always going to be 'AAAA ##.##'? Meaning is the value always going to be 4 letters followed by a space?
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
Hi, split the problem in a couple of smaller ones. There are at least two parts: 1. locate the "word" that contains the number 2. translate that word to a numeric value 1. depends on what you do know about the pattern in the string. e.g. if the number is always at the end, find the last space, get the substring behind it. if there is exactly one word plus a space in front, find that first space and look for a possible space after the number too. 2. is easy with int.Parse or int.TryParse If you were really lazy (I wouldn't dare to assume that), split the entire string in words based on a space, then foreach "word" do a TryParse until one succeeds. And now you are on your own I guess. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets