Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

String Example

using System.IO;
using System;

class Program
{
    static void Main()
    {        
        //Show Date
        DateTime date = new DateTime(2019,02,23);
        string date1 = date.ToString("M");
        string date2 = date.ToString("Y");
        string date3 = date.ToString("D");
        
        Console.WriteLine("Date : {0}", date);
        Console.WriteLine("Date : {0}", date1);
        Console.WriteLine("Date : {0}", date2);
        Console.WriteLine("Date : {0}", date3);
        
        //Make Substring
        string str = "Umbrella";
        string subStr1 = str.Substring(2,4);
        string subStr2 = str.Substring(0,6);
        
        Console.WriteLine("String : {0}", str);
        Console.WriteLine("Substring : {0}", subStr1);
        Console.WriteLine("Substring : {0}", subStr2);
        
        //Length of a String
        Console.WriteLine("String Length : {0}", str.Length);
        Char[] charArray = str.ToCharArray();
        Console.WriteLine("String Length : {0}", charArray.Length);
        Char[] revCharArray = new Char[charArray.Length];
        
        //Reverse of String
        revCharArray = charArray;
        Array.Reverse(revCharArray);
        string revStr1 = new String(revCharArray);
        Console.WriteLine("String : {0}", str);
        Console.WriteLine("Reverse String1 : {0}", revStr1);
        string revStr2 = "";
        int ind = str.Length - 1;
        while( ind >= 0)
        {
            revStr2 += str[ind];
            ind--;
        }
        Console.WriteLine("Reverse String2 : {0}", revStr2);
        
        // Concatenate Strings
        string fname = "Asif";
        string sname = "Kamal";
        Console.WriteLine("Full Name : {0}", String.Concat(fname," ",sname));
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.