Last Number

  • Thread starter Thread starter Craig Brunton
  • Start date Start date
C

Craig Brunton

Hi all,

I have a text box in which the user will enter a 4 digit number.

What I want to do is look at the last digit to see if it is a zero.

Is this possible?

Thanks in advance

Craig Brunton
 
Hi,



Dim strNum As String = "2432450"

Dim intLast As Integer

Try

Dim strLast As String = strNum.Substring(strNum.Length - 1)

intLast = CType(strLast, Integer)

If intLast = 0 Then

MessageBox.Show("Last number is zero")

End If

Catch ex As Exception

End Try



Ken
 
Hi,



Dim strNum As String = "2432450"

Dim intLast As Integer

Try

Dim strLast As String = strNum.Substring(strNum.Length - 1)

intLast = CType(strLast, Integer)

If intLast = 0 Then

MessageBox.Show("Last number is zero")

End If

Catch ex As Exception

End Try

To my mind, the following is cleaner:

If txtDigits.Text.Trim.EndsWith("0") Then
MsgBox("It ends with zero!")
End If
 
Back
Top