TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajagopalan R V
NA
336
70.6k
Reverese the Odd Strings
Aug 25 2015 6:53 AM
Hi Friends.,
Here We Going to Reverse the Odd Number Strings and not the Even Strings (Even Strings) Will Display like As Entered.
In .aspx Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Convert.aspx.cs" Inherits="Convert" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Label ID="lblEnterText" Text="Enter Your Text Here :" runat="server" Font-Bold="true"></asp:Label>
<asp:TextBox ID="tbxInputText" runat="server" Width="500px" Height="100px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnConvert" Text="Convert" runat="server" OnClick="btnConvert_Click">
</asp:Button>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblOutPutText" Text="Output for Given Text : " runat="server" Font-Bold="true"></asp:Label>
<asp:TextBox ID="tbxOutputText" runat="server" Width="500px" Height="100px" TextMode="MultiLine"
ReadOnly="true" Font-Bold="true"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
In .aspx.cs Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Convert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void btnConvert_Click(object sender, EventArgs e) //Button Click to Convert the Text.
{
string Text = tbxInputText.Text; // Assigning Text Box Value to String
int j = 0; // Declared Count of J = 0
string K = string.Empty; // Declared string K as Empty New string.
DataTable dt = new DataTable();
dt.Columns.Add("text"); //Creation of New DataTable to Bind the Splitted "string Text" Value in New Column "text".
for (int i = 0; i < Text.Length; i++) //Loop Created based on String Length it will Enter.
{
if (Text[i].ToString() == " ")
{
dt.Rows.Add(); //Adding New Rows in the DataTable.
dt.Rows[j][0] = K.ToString(); // Assigning K Value to Created DataTable.
j++; //To add Row
K = " "; // To Clear K Value for Further Use.
}
else if (i == Text.Length - 1) // To Bind the Last Value in the DataTable.
{
K = K + Text[i];
dt.Rows.Add(); //Adding New Rows in the DataTable.
dt.Rows[j][0] = K.ToString(); // Assigning K Value to Created DataTable.
j++; //To add Row
K = " "; // To Clear K Value for Further Use.
}
else // To Bind the Text Value to Form a Word.
{
K = K + Text[i];
}
}
string M = "";
string y = "";
for (int i = 0; i < dt.Rows.Count; i++) // Based on Count Loop Will Execute
{
if (i % 2 == 0) // if i Mod of 2 = 0 that Current Row Value in dt Will get Bind in M. It Will Bind Direct Values Which we give.
{
M = M + dt.Rows[i][0].ToString(); // Binding Direct Value here
}
else
{
string x = dt.Rows[i][0].ToString(); //It will Bind the Row Value in string x if i=1 it won't be Zero for i Mod 2 = 0 that kind of Value will get bind here
for (int z = x.Length - 1; z > 0; z--) // z-- will do count from greater to lesser for e.g : 6 to 1 it is used to bind Values in Reverese
{
y = y + x[z]; //Where y the Binded Value + x is Next Word [z] is Count.
}
M = M + " " + y; // Where M Already Bounded value + Space + Y Value (Reverese String)
y = ""; // to Clear Y Value to Use for Further.
}
}
tbxOutputText.Text = M.ToString(); // At the End M will get Whole Sentence as we need to Bind the M input to Textbox to Display.
}
}
Reply
Answers (
4
)
how to create a dynamic theam changing in mvc rasor coding
Basic example of Serialization in JSON using Asp.net.