How to Reverse string using asp.net


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>


Comments

No responses found. Be the first to 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:
    Email: