Comparing a String to the Beginning or End of a Second String

image_pdfimage_print

   
  

using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
class Class1{
        static void Main(string[] args){
      string head = "str";
      string test = "strVarName";
      Console.WriteLine(test.StartsWith(head));

      string tail = "Name";
      test = "strVarName";
      Console.WriteLine(test.EndsWith(tail));
        
    
    
      head = "str";
      test = "strVarName";
      Console.WriteLine(string.Compare(head, 0, test, 0, head.Length, true));

      tail = "Name";
      test = "strVarName";
      Console.WriteLine(string.Compare(tail, 0, test, (test.Length - tail.Length), tail.Length, true));
        }
}

           
         
    
     


This entry was posted in Data Types. Bookmark the permalink.