ASP.Net – String Function

 1.    Substring(start index, substring length)

C# Substring function returns a part of specified string.

String strname  = ”meera Academy”;

–  String stroutput  = strname.Substring(2 , 5);

  Answer = “era A”;



 2. Split()  Use Split to separate parts from a string. If your input string is “A,B,C” you can split on the comma to get an array of: “A” “B” “C”.

String  sname  = ” there is a dog”;

String []  output = sname.Split(‘   ‘);

for(int i=0; i<=output.Length – 1; i++)

{  
  Response.write(output[i]); 
}


 3.   Length(String.Length)

C# String Length function returns the total number of characters in the specified string.

– string strname = ”meera”;

– Ouput = strname.Length;

Answer  =  5;


 4.   Remove(start index, Removestring length)

– C# Remove String function returns the string value by deleting the specified set of characters.

String  strText = “MeeraAcademy”;

– Response.Write(strText.Remove(2 , 3));

– Answer =  “ MeAcademy”;

 5.  Replace(Old String, New String)

C# Replace String function replaces the specified string pattern or character with new string or   character from the string value.

– String  strText   = “MeeraAcademy”;

– Response.Write(strText.Replace(“my”, “MY”));

– Answer = “MeeraAcadeMY”;

 6.    StratsWith()


 string strText = “ASP.Net C# string.StartsWith function”;

–  Response.Write(strText.StartsWith(“ASP.Net”));  =  True

–  Response.Write(strText.StartsWith(“S”) );          =  False

 7. EndsWith()

 – String strText = “ASP.Net C# string.EndsWith function”;

–   Response.Write(strText.EndsWith(“tion));      =  True

–   Response.Write(strText.EndsWith(“tio”) );      =  False


Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 2 =