views:

244

answers:

4

i want to get the last 5 digits/strings from a strings of words. eg: "I will be going to school in 2011!"

i am using visual studio.net 2008 and using vb.net.

i will like to get "2011!"

note, my strings changes, and the last 5 characters can be anything! any ideas.

i know visual basic have Right(string, 5); this didn't work for me gave me an error. thanks

+1  A: 
str.Substring(str.Length - 5)
dcp
wonderful, works like a charm!
Menew
A: 

You're looking for the Substring method.

Hank Gay
+1  A: 

Checks for errors:

Dim result As String = String.Empty
If str.Length >=5 Then
    result = str.Substring(str.Length - 5)
End If
Nick Gotch
A: 

Error check:

result = str.Substring(Math.Max(0, str.Length - 5))
Glennular