dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPhagu Mahato
Abul Bashar Sardar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » .NET »

Reverse The String Programme In C sharp


Posted Date: 04 Jul 2012      Posted By:: amjad     Member Level: Silver    Member Rank: 1031     Points: 1   Responses: 9



Hi,

My String Name Is : WELCOME TO INDIA

I want Reverse The String Programme In Csharp


O/P : EMOCLEW OT AIDNI




____________________________________________________

Thanks & Regards
AMJAD
http://update-dotnet.blogspot.com/
http://updatedotnet.wordpress.com/
http://update-dotnet.blogspot.com/




Responses

#678863    Author: amjad      Member Level: Silver      Member Rank: 1031     Date: 04/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Hai ,

With Out Using any Reverse Function

____________________________________________________

Thanks & Regards
AMJAD
http://update-dotnet.blogspot.com/
http://updatedotnet.wordpress.com/
http://update-dotnet.blogspot.com/



 
#678871    Author: Paritosh Mohapatra      Member Level: Diamond      Member Rank: 6     Date: 04/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Please check the following code:


protected void Button1_Click(object sender, EventArgs e)
{
string OriginalString = "WELCOME TO INDIA";
string ReverseString = GetReverseString(OriginalString);
Response.Write(ReverseString);
}

public string GetReverseString(string OriginalString)
{
string ReverseString="";
for (int i = OriginalString.Length - 1; i >= 0; i--)
{
ReverseString += OriginalString[i];
}
return ReverseString;
}



Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM



 
#678872    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 19     Date: 04/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

You should be using "Reverse" function. There is no harm to use that.
But, if you don't want to use that, below is what you're looking for:


string str = "WELCOME TO INDIA";
string[] op = str.Split(' ');
str = String.Empty;
foreach (string s in op)
{
for (int i = s.Length - 1; i >= 0; i--)
{
str += s[i];
}
str += " ";
}


Hope it'll help you.
Regards
Ajatshatru






 
#678906    Author: chandramohan      Member Level: Gold      Member Rank: 221     Date: 04/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

package com.example.string;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
public class StringLibrary {
private String reverseStringWordWise(String input)
{
char arr[]=input.toCharArray();
int len=arr.length;
int space[] = new int[len];
int i=0;
int pos=0;
//Finding position of spaces
for(i=0;i<len;i++)
{
if (arr[i]==' ')
{
space[pos]=i;
pos++;
System.out.println(i);
}
}
if(pos==0)
{
return input;
}
String output=new String(input.substring(space[pos-1]+1));
int spaceIndex=0;
while(spaceIndex<pos-1)
{
output=output.concat(" "+input.substring(space[pos-spaceIndex-2]+1,space[pos-1-spaceIndex]));
spaceIndex++;
}
output =output.concat(" "+input.substring(0,space[0]));
return output;
}
public static void main(String[] args) {
StringLibrary st=new StringLibrary();
String test="This is just a test string";
System.out.println(st.reverseStringWordWise(test));
System.out.println(st.reverseStringWordWise("hello world"));
System.out.println(st.reverseStringWordWise("There has been some effort to make this progarm work"));
}
}



 
#678910    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 04/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

You can take all the words in separate array and then reverse 3each of the the array to get the reverse value


Array myArray=Array.CreateInstance( typeof(String), 9 );
Array.Reverse( myArray );


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
#678941    Author: Ultimaterengan        Member Level: Gold      Member Rank: 9     Date: 05/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4


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>





Thanks & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!


http://renganathan1984.blogspot.com/



 
#679236    Author: amjad      Member Level: Silver      Member Rank: 1031     Date: 06/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

@ Friends ,,,

Please Observe The OUTPUT

I want Output : EMOCLEW OT AIDNI

But Above All code am Getting OUT PUT : AIDNI OT EMOCLEW

____________________________________________________

Thanks & Regards
AMJAD
http://update-dotnet.blogspot.com/
http://updatedotnet.wordpress.com/
http://update-dotnet.blogspot.com/



 
#679239    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 19     Date: 06/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

I think you did not check my code snippet.
It will give you the output what you want.
I would suggest you to go through the code.

Hope it'll help you.
Regards
Ajatshatru



 
#679257    Author: amjad      Member Level: Silver      Member Rank: 1031     Date: 06/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

@Ajatshatru

Thanks Allot ,,,,

It's Working Fine

____________________________________________________

Thanks & Regards
AMJAD
http://update-dotnet.blogspot.com/
http://updatedotnet.wordpress.com/
http://update-dotnet.blogspot.com/



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : DotNet integration with SalesForce
Previous : Export csv file and import the export csv file in excel
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    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.