|
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:  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:  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:  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:  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:  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
| #679236 Author: amjad Member Level: Silver Member Rank: 1031 Date: 06/Jul/2012 Rating:  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:  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:  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. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|