string method

  • Thread starter Thread starter July
  • Start date Start date
J

July

How do you detect a string's right 3 charaters, say
string "abcde". I'd like to detect if the right three
charaters are "cde", then proceeding doing something.
Anyone know which method shall I use? Thanx.
 
Hi

Given the fact that
a) VB.Net is completel;y objectoriented
b) Microsoft.Visualbasic namespace is given for backward
compatibility

suggest that u use the String Object props/methods like
length, substring instead of Functions like Right()

The following code sniper will do wat u want.
Watch for Line wraps

Right("abcde", 3) ' Will Return "cde"

Sub Right(ByVal p_strData As String, ByVal
p_intNoOfCharsToGet As Integer)
If Not p_strData Is Nothing AndAlso
p_strData.Length >= p_intNoOfCharsToGet Then
Console.WriteLine(p_strData.Substring
((p_strData.Length - p_intNoOfCharsToGet),
p_intNoOfCharsToGet))
End If
End Sub

regards,

sr
 
Keith Patrick said:
Since we're talking .Net here, try String.EndsWith(string)

Doh! That'll teach me to not bother looking at the MSDN to see whether
there's a better way than using primitive tools such as Length, IndexOf
and Substring :)
 
try regular expressions
they can find just about anything and return the "other"
stuff as well
lots of examples
 
Back
Top