Aim:
To perform the using string handling function program using c sharp.net application.Algorithms:
Step1: Start the program.Step2: Open the new text document
Step3: Type the program in the text document
Step4: Create the class which the name as strops.
Step5: Initialize the string variables as str1 str2 str3
Step6: Using the strop and strlow functions to displays the string in capital letters and small letters.
Step7: Using the some handlings functions like string length, string concatenation, string lower case, string trim, string reverse and string comparisons are used in this program.
Step8: Compile and run the program.
Program:
using System;
using System.Globalization;
class Strops
{
static void Main()
{
string str1 = "Ramakrishna Mission Vidyalaya";
string str2 = "Ramakrishna Mission Vidyalaya";
string str3 = "Vivekananda University";
string strUp, strLow;
int result, idx;
Console.WriteLine("str1: " + str1);
Console.WriteLine("Length of str1: " + str1.Length);
Console.WriteLine("str2: " + str2);
Console.WriteLine("Length of str2: " + str2.Length);
Console.WriteLine("str3: " + str3);
Console.WriteLine("Length of str3: " + str3.Length);
strLow = str1.ToLower(CultureInfo.CurrentCulture);
strUp = str1.ToUpper(CultureInfo.CurrentCulture);
Console.WriteLine("Lowercase version of str1:\n " + strLow);
Console.WriteLine("Uppercase version of str1:\n " + strUp);
Console.WriteLine("orgstr: " + str1);
string split = string.Empty;
string[] strarr = str1.Split(' ');
Console.WriteLine("split a string: ");
for (int i = strarr.Length -1; i >= 0; i--)
{
Console.WriteLine(strarr[i]);
}
string substr = str1.Substring(11, 16);
Console.WriteLine("substr: " + substr);
string input = str1;
char[] inputarray = input.ToCharArray();
Array.Reverse(inputarray);
string output = new string(inputarray);
Console.WriteLine("strrev: " + output);
Console.WriteLine();
Console.WriteLine("Display str1, one char at a time.");
for(int i=0; i < str1.Length; i++)
Console.WriteLine(str1[i]);
if(str1 == str2)
Console.WriteLine("str1 == str2");
else
Console.WriteLine("str1 != str2");
if(str1 == str3)
Console.WriteLine("str1 == str3");
else
Console.WriteLine("str1 != str3");
result = string.Compare(str1, str3, StringComparison.CurrentCulture);
if(result == 0)
Console.WriteLine("str1 and str3 are equal");
else if(result < 0)
Console.WriteLine("str1 is less than str3");
else
Console.WriteLine("str1 is greater than str3");
Console.WriteLine();
Console.WriteLine ("One Two Three One");
Console .WriteLine ();
str2 = "One Two Three One";
idx = str2.IndexOf("One", StringComparison.Ordinal);
Console.WriteLine("Index of first occurrence of One: " + idx);
idx = str2.LastIndexOf("One", StringComparison.Ordinal);
Console.WriteLine("Index of last occurrence of One: " + idx);
Console.ReadLine();
}
}
OUTPUT:
BY
REGU RAM SV.
Post a Comment