use the StartsWith() and EndsWith() methods to check if a string contains a specified substring at the start and end

image_pdfimage_print
   
 


using System;

class MainClass {

    public static void Main() {
        string[] myStrings = {"To", "be", "or", "not","to", "be"};
        string myString = String.Join(".", myStrings);        
        Console.WriteLine("myString = " + myString);
        if (myString.StartsWith("To")) {
            Console.WriteLine("myString starts with "To"");
        }
        if (myString.EndsWith("be")) {
            Console.WriteLine("myString ends with "be"");
        }

    
    }
}

    


use the Copy() method to copy a string

image_pdfimage_print
   
 

using System;

class MainClass {

    public static void Main() {
        string myString4 = String.Concat("Friends, ", "Romans");
        Console.WriteLine("myString4 = " + myString4);
        Console.WriteLine("Copying myString4 to myString7 using Copy()");
        string myString7 = String.Copy(myString4);
        Console.WriteLine("myString7 = " + myString7);
    
    }
}

    


create some strings

image_pdfimage_print
   
 

using System;

class MainClass {

    public static void Main() {
        
        string myString = "To be or not to be";
        string myString2 = "...	 that is the question";
        string myString3 = @"	 Friends, Romans, countrymen,
lend me your ears";

        // display the strings and their Length properties
        Console.WriteLine("myString = " + myString);
        Console.WriteLine("myString.Length = "
          + myString.Length);
        Console.WriteLine("myString2 = " + myString2);
        Console.WriteLine
         ("myString2.Length = " + myString2.Length);
        Console.WriteLine("myString3 = " + myString3);
        Console.WriteLine
          ("myString3.Length = " + myString3.Length);    
    }
}

    


Is Palindrome

image_pdfimage_print

using System;
using System.Text;

public class MainClass {
public static bool IsPalindrome(string s) {
int iLength, iHalfLen;
iLength = s.Length – 1;
iHalfLen = iLength / 2;
for (int i = 0; i <= iHalfLen; i++) { if (s.Substring(i, 1) != s.Substring(iLength - i, 1)) { return false; } } return true; } static void Main(string[] args) { string[] sa = new string[]{"level", "minim", "radar"}; foreach (string v in sa) Console.WriteLine("{0} {1}",v, IsPalindrome(v)); } } [/csharp]