Right. These functions live on in the .NET Framework, but they live in the dreaded Microsoft.VisualBasic namespace, a namespace both shunned and feared by many. But do not loose hope, fair .NET programmer, for there is a “pure” way to easily reproduce the functionality of the
Rightfunction with out resorting to the Microsoft.VisualBasic namespace methods.
All silliness aside, there is a simple way to reproduce the functionality of the
Rightfunctions using non-Microsoft.VisualBasic namespace methods. The typically answer to this question is to use the Substring method, but the
Substringmethod requires to use valid
In VB6 if you had a three-character string called TestString and called
Left(TestString, 5), you would get your three-character string back. In .NET if you were to have this same string and call
TestString.Substring(0, 5)method, you would get a ArgumentOutOfRangeException exception.
I colleague of mine came up with the following way to reproduce the functionality of the old VB6
TestString.Substring(0, Math.Min(5, TestString.Length))
The old VB6
Rightfunction can be reproduced by using the following:
TestString.Substring(TestString.Length – Math.Min(5, TestString.Length), Math.Min(5, TestString.Length))