tags:

views:

58

answers:

2

I need some kind of code to check if the first line in a richtextbox contains numbers or not.

Something like this:

If Richtextbot1.Lines(0) contains Numbers Then
Goto startbot
Else
End If

Here is an example of my richtextbox lines:

  1. 2245 queen st west, ON, M6R2W7

  2. 12 RRw Rd, ON

  3. ON, M2N4E3

If the first line contains 4 or more numbers, it will use it. After each loop it will delete line 1. So it repeats for the next line. When my code reaches the 3rd line, and it doesnt find 4 or more numbers it needs to delete the line.

A: 

You could simply iterate through the characters in the line looking for one that is a digit based on the premise that if you find a digit you'll be able to find what you term a 'number.'

Public Function DoesLineContainNumber() As Boolean
    For index As Integer = 0 To RichTextBox1.Lines(0).Length - 1
        If Char.IsDigit(RichTextBox1.Lines(0)(index)) Then
            Return True
        End If
    Next
    Return False
End Function

You could then extract these 'numbers' by parsing the string starting with the first digit found.

Simple Simon
Thanks Simon. One more thing though, how can I edit the function so it checks if the line contains 4 or more numbers? I should have mention this in the start.
Infodayne
You have to define 'number'. Do you mean single digits like 1, 2, 3, 4, etc... or do you mean numbers like 4, 56, 123, 9876, etc... Do you mean decimal, hexadecimal, octal or some other base of number? Can these be floating point numbers like 1.23, 7.21e-3, etc...? Once you define what you mean by number then you can write a parser or perhaps even a regex expression to determine how many 'number' there are in the line.
Simple Simon
Here is an example of my richtextbox lines:LINE1:2245 queen st west, ON, M6R2W7LINE2:12 RRw Rd, ON, M8R4W5LINE3:ON, M2N4E3If the first line contains 4 or more numbers, it will use it. After each loop it will delete line 1. So it repeats for the next line. When my code reaches the 3rd line, and it doesnt find 4 or more numbers it needs to delete the line.
Infodayne
Do me a favor, add the information in your last comment to the original post. That way your post will appear back on the active post page.
Simple Simon
A: 

Try this

Dim firstLineContainsNumber As Boolean = ContainsNumber(RichTextBox1.Lines(0))
...

Public Function ContainsNumber(input As String) As Boolean         
    Dim myRegex As New Regex("\d")        
    Return (myRegex.IsMatch(input))        
End Function
p.campbell