In this post, we will learn how to handle string operations for common methods.
When I planned to migrate the VB6 products to .NET technologies, I thought VB.NET is a better choice since it has the similarity of VB6 and it has most predefined functionalities.
I have the knowledge of Visual Basic 6 and wished to learn a new language so I preferred C# .NET. But I faced a lot of problems to find the functionalities equivalent to VB6 while migrating to C# Winforms. Finally, after a lot of research, I got the solution, that is shared below with you.
Here, I have included the methods for String operations of Left, Right, Mid, and Instring.
When I planned to migrate the VB6 products to .NET technologies, I thought VB.NET is a better choice since it has the similarity of VB6 and it has most predefined functionalities.
I have the knowledge of Visual Basic 6 and wished to learn a new language so I preferred C# .NET. But I faced a lot of problems to find the functionalities equivalent to VB6 while migrating to C# Winforms. Finally, after a lot of research, I got the solution, that is shared below with you.
Here, I have included the methods for String operations of Left, Right, Mid, and Instring.
Find the below code for the Right string.
- public static string strRight(string strValue, int intLength)
- {
- string strRet = string.Empty;
- try
- {
- strRet = strValue.Substring(strValue.Length - intLength);
- }
- catch (Exception ex)
- {
- strRet = strValue;
- }
- return strRet;
- }
- public static string strLeft(string strValue, int intLength)
- {
- string strRet = string.Empty;
- try
- {
- if (string.IsNullOrEmpty(strValue)) strRet = strValue;
- intLength = Math.Abs(intLength);
- strRet = strValue.Length <= intLength ? strValue : strValue.Substring(0, intLength);
- }
- catch (Exception ex)
- {
- strRet = strValue;
- }
- return strRet;
- }

Join the conversation! Your thoughts help the community grow.