String functions in C#
Today we are going to learn about string functionalities in C#. It is very essential to know the basic string functionalities.So that we can easily work with strings.Here I have listed few functionalities.I hope it would be more helpful.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace StringFunctionalities
{
public class Program
{
public static void Main(string[] args)
{
//Display string
string myString="Nothing will be interesting if you are not interested";
Console.WriteLine(myString);
//output:Nothing will be interesting if you are not interested
//Reversting the string
char[] reversedString=myString.ToCharArray();
Array.Reverse(reversedString);
Console.WriteLine(reversedString);
//output:detseretni ton era uoy fi gnitseretni eb lliw gnihtoN
//Converting to upper case
Console.WriteLine(myString.ToUpper());
//output:NOTHING WILL BE INTERESTING IF YOU ARE NOT INTERESTED
//Converting to lower case
Console.WriteLine(myString.ToLower());
//output:nothing will be interesting if you are not interested
//Selecting specfic text
Console.WriteLine(myString.Substring(15, 12 ));
//output:interesting
//Replacing the specific text to other
Console.WriteLine(myString.Replace("will","would"));
//output:Nothing would be interesting if you are not interested
//Removing the specific text
Console.WriteLine(myString.Remove(15, 12));
//output:Nothing will be if you are not interested
//Calculating the length of a string
Console.WriteLine("Length = "+ myString.Trim().Length);
//output:Length = 53
//Displaying doublt quotes inside the string
Console.WriteLine("My father told \"you can achieve it\" .");
//output:My father told "you can achieve it" .
}
}
}
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace StringFunctionalities
{
public class Program
{
public static void Main(string[] args)
{
//Display string
string myString="Nothing will be interesting if you are not interested";
Console.WriteLine(myString);
//output:Nothing will be interesting if you are not interested
//Reversting the string
char[] reversedString=myString.ToCharArray();
Array.Reverse(reversedString);
Console.WriteLine(reversedString);
//output:detseretni ton era uoy fi gnitseretni eb lliw gnihtoN
//Converting to upper case
Console.WriteLine(myString.ToUpper());
//output:NOTHING WILL BE INTERESTING IF YOU ARE NOT INTERESTED
//Converting to lower case
Console.WriteLine(myString.ToLower());
//output:nothing will be interesting if you are not interested
//Selecting specfic text
Console.WriteLine(myString.Substring(15, 12 ));
//output:interesting
//Replacing the specific text to other
Console.WriteLine(myString.Replace("will","would"));
//output:Nothing would be interesting if you are not interested
//Removing the specific text
Console.WriteLine(myString.Remove(15, 12));
//output:Nothing will be if you are not interested
//Calculating the length of a string
Console.WriteLine("Length = "+ myString.Trim().Length);
//output:Length = 53
//Displaying doublt quotes inside the string
Console.WriteLine("My father told \"you can achieve it\" .");
//output:My father told "you can achieve it" .
}
}
}
Comments
Post a Comment