Sunday, 6 July 2014

String First And Last Character by Substring in C#

Let say you have a string and you want its first or last character like first 2 or last 4 how could you do that?

here is sample for that


string mystring = "122014";
      
        mystring = mystring.Substring(mystring.Length - 4);
        Response.Write(mystring.ToString());


//output:2014


 mystring = "122014";
        string sub = mystring.Remove(mystring.Length - 4);
        Response.Write("<br>");
        Response.Write(sub.ToString());


//output: 12

No comments:

Post a Comment

Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...