One of my friend ask me about how we can get:
·
Length of the string
·
Number of occurrence of character i.e. Z
·
Remove the character from the string
·
Length after excluding the character i.e. Z
here is the sample code:
protected void LENGTH()
{
string strLen = "ZBCZDGHSZKHZHDZ";
Response.Output.Write("String including character 'Z': " + strLen + "");
int len = strLen.Length;
Response.Output.Write("Total string length: " + len + "");
int count = strLen.Split('Z').Length - 1;
Response.Output.Write("No of occurance of character 'Z': " + count + "");
string strFinalString =
strLen.Replace("Z",
string.Empty);
Response.Output.Write("String after excluding character 'Z': " + strFinalString + "");
Response.Write("Length after excluding character 'Z': " + strFinalString.Length);
}
I hope you will enjoy the topic.
Cheers
Comments