Left, Right and Mid String Functions for C#

Left, Right and Mid String Functions for C#

Unlike Visual Basic, C# doesn’t have built-in string methods to extract parts of string from the Left, Right or a location specified through Mid. Unfortunately you have to create the logic yourself.

Here are examples of Left, Right and Mid in C# with the use of the Substring method present in C# (and VB):

class LeftRightMid   {      [STAThread]      static void Main(string[] args)      {            string myString = "This is a string";         //Get 4 characters starting from the left         Console.WriteLine(Left(myString,4));         //Get 6 characters starting from the right         Console.WriteLine(Right(myString,6));            //Get 4 characters starting at index 5 of the string         Console.WriteLine(Mid(myString,5,4));         Console.ReadLine();      }      public static string Left(string param, int length)      {         string result = param.Substring(0, length);         return result;      }       public static string Right(string param, int length)      {         string result = param.Substring(param.Length - length, length);         return result;      }      public static string Mid(string param,int startIndex, int length)      {         string result = param.Substring(startIndex, length);         return result;      }   }}
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved