Right function

  • Thread starter Thread starter Domac
  • Start date Start date
Private Function GetRight(ByVal InitialString As String, ByVal
NumOfChars As Integer) As String
If InitialString.Length >= NumOfChars Then
Return InitialString.Substring(InitialString.Length -
NumOfChars, NumOfChars)
Else
Return InitialString
End If
End Function

Aristotelis
 
It's still there, as previous posters pointed out. It's just a wrapper
around the methods in the String class, though.

This is how it's implemented:

Public Shared Function Right(ByVal str As String, ByVal Length As
Integer) As String
If (Length < 0) Then
Throw New
ArgumentException(Utils.GetResourceString("Argument_GEZero1", New
String() { "Length" }))
End If
If ((Length = 0) OrElse (str Is Nothing)) Then
Return ""
End If
Dim num1 As Integer = str.Length
If (Length >= num1) Then
Return str
End If
Return str.Substring((num1 - Length), Length)
End Function

If you know that the values you use are sane, you only need the code
from the last line.


If you only want to check the contents of the end of the string, there
are neater methods in the string class.

If Right(str, 4) = ".jpg" Then

translates into:

If str.EndsWith(".jpg") Then
 
It's still there, as previous posters pointed out. It's just a wrapper
around the methods in the String class, though.

Goran are you sure of that?

Because AFAIK is there more times written that this is sometimes the
situation for Visual Basic functions, however not forever.

Cor
 
Cor Ligthert said:
Goran are you sure of that?

Because AFAIK is there more times written that this is sometimes the
situation for Visual Basic functions, however not forever.

According to the formatting style the code posted by Goran has been
extracted using Reflector or a similar tool.
 
Cor said:
Goran are you sure of that?

Because AFAIK is there more times written that this is sometimes the
situation for Visual Basic functions, however not forever.

Cor

If I correctly interpret what you are trying to say, you are saying that
several times it has been written that some of the Visual Basic
functions are wrappers, but not all of them?

Just as Herfried suspected, I have used Lutz Roeder's .NET Reflector to
look at the code in the Microsoft.VisualBasic library. The code that I
posted is how the actual Right method is implemented.
 
Goran,

Than I won't call this "It's just a wrapper", for me this is a wrapper plus
something extra.

Cor
 
Yes, you are right, there is a bit of logic there also.

Perhaps "Not much more than a wrapper" would have been a more suitable
description.
 
Back
Top