Subscribe to Subscribers
Talk to Webmaster Tony John

Resources » Code Snippets » ASP.NET WebForms

How to Reverse string using asp.net


Posted Date:     Category: ASP.NET WebForms    
Author: Member Level: Gold    Points: 15


In this article I'm going to explain how to reverse a string using asp.net.



 



In this article I'm going to explain how to reverse a string using asp.net.
Here we have a two text box and one button control.
we have to reverse the string inside the text box and print that out on another text box by clicking Reverse button.



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
#region "Reverse Click Event"
protected void btnReverse_Click(object sender, EventArgs e)
{
TextBox2.Text = ToReverseString(TextBox1.Text.ToString());
}
#endregion
#region "ReverseString"
public string ToReverseString(string strInputString)
{
//take one new string
string strFinalString = string.Empty;
for (int count = strInputString.Length - 1; count >= 0; count--)
{
//store the reverse character in seperate string
strFinalString = strFinalString + strInputString[count];
}
return strFinalString;
}
#endregion
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 530px">
<tr>
<td style="width: 100px">
Enter the String
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="btnReverse" runat="server" OnClick="btnReverse_Click" Text="Reverse" /></td>
</tr>
<tr>
<td style="width: 100px">
Reverse String
</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>






Did you like this resource? Share it with your friends and show your love!


Responses to "How to Reverse string using asp.net"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to create Dynamic Image button using asp.net
    Previous Resource: How to integrate PayPal in ASP.NET using cart option ?
    Return to Resources
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    How to Reverse string using asp.net  .  
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.