Create Left, Right and mid method in C#

In this article show how to create left, right, and mid method by using Substring and calling these method in C#.

Create Method:
  
1. Left method 

  Public string left(string word,int lenght)
  {
    Return word.Substring(0, lenght);
  }

2. Right method

  Public string right(string word,int lenght)
  {

    Return word.Substring((word.Length–length) , lenght);
  }

  3. Mid method

  Public string mid(string word,int startindex, int lenght)
  {
     Return word.Substring(startindex,lenght); 

  }

Calling method in form load:

   string result;
   string word = "Hello world";
   result = word.Substring(2);
   //result = llo world
   MessageBox.Show(result);
   result = right(word, 2);
   //result = ld
   MessageBox.Show(result);
   result = left(word,3);
   //result = Hel
     MessageBox.Show(result);
      
  result = mid(word, 2, 5);

  //result = llo w
  MessageBox.Show(result);

 
Hope this post is helpful for you ...:) :)
Create Left, Right and mid method in C# Create Left, Right and mid method in C# Reviewed by BeiLover on 7:13 PM Rating: 5

No comments:

Powered by Blogger.