// Program to demonstrate sting funtions
//Instance level funtions: ToUpper(), ToLower(), Trim(), Split(), IndexOf(), LastIndexOf(), Substing(), Contains
//Static Funtions: Concat()
using System;
class Program
{
static void Main()
{
string s1,s2;
s1="Hello";
s2="World";
s1=string.Concat(s1,s2);
Console.WriteLine("Cancat Result: {0}",s1);
Console.WriteLine("Upper Result: {0}",s1.ToUpper());
Console.WriteLine("Lower Result: {0}",s1.ToLower());
bool b=s1.Contains("World");
Console.WriteLine("Contains Result: {0}",b);
int n=s1.IndexOf("llo");
Console.WriteLine("IndexOF Result: {0}",n);
n=s1.LastIndexOf('l');
Console.WriteLine("LastIndexOf Result: {0}",n);
Console.WriteLine("Substring Result: {0}",s1.Substring(3));
Console.WriteLine("substring Result: {0}",s1.Substring(3,5));
s2=" Ankur Bhatnagar ";
Console.WriteLine("Before Trim Result: {0}",s2.Length);
s2=s2.Trim();
Console.WriteLine("After Trim Result: {0}",s2.Length);
s2="ASP.NET,C#.NET,VB.NET";
string[] str=s2.Split(',');
Console.WriteLine("Split Result:");
foreach(string item in str)
{
Console.WriteLine("{0}",item);
}
}
}
No comments:
Post a Comment