Click here to Skip to main content
12,549,003 members (48,639 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
Hi All,

I have a string I need to reverse. I was looking for the simplest way (as always!)
so have tried the string to see if that exists, it doesn't or I can't find it.
MSDN have lots of suggestions along the lines of
Console.WriteLine("Pleae enter a string, print enter to end");
string input = Console.ReadLine();
StringBuilder sb = new StringBuilder();
int i = input.Length-1;
while (i != - 1)
Console.WriteLine("Reverse stirng is " + sb.ToString());
which seems to be a the correct way of doing it I just now
need to get the sb the string builder "variable" to equal a string for the next bit of editing it need as a string for the next bit of processing.
if I do sb = Next (Next is a string) I get the Error Cannot implicitly convert type 'string' to 'System.Text.StringBuilder'. So two questions is this the right way, if so how do I get a string out it, if not what is the right way?
Posted 22-Jan-13 5:20am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

LINQ could be another approach you could consider.
String Reversal[^] discusses three approaches to reverse a string.
Sergey Alexandrovich Kryukov 22-Jan-13 11:45am
Nice and kinda comprehensive, a 5.
Abhinav S 22-Jan-13 11:56am
Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Did you try searching? This was the first hit for 'c# string reverse' and answers your question. It seems the Array.Reverse approach is the best.
glennPattonWork 22-Jan-13 11:34am
Only on MSDN really, found a method and tried sb.ToString() sorted out my problem, I will have a look at that now....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100