+ 1

How to reverse a string In C#

How to reverse the word that string contain!

29th Apr 2020, 12:11 PM
Siddhant Pandav
Siddhant Pandav - avatar
3 Answers
+ 1
There are several ways - in java you can turn your String into a set of characters e.g. "mystring" = 'm' + 'y' + 's' + 't' + 'r' + 'i' + 'n' + 'g' Then you use a simple for loop and and reverse it for (int i = myString.Length; i = 0; i--) { reversedString += mystring.charAt( i); } This is just pseudocode so you'll have to check the proper implementation - try looking for charAt equivalent for C# There's other reverse methods already implemented in the language
29th Apr 2020, 12:34 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 3
Give it a try and post your logic atleast. You don't learn anything if the answers come with a spoon.
29th Apr 2020, 2:17 PM
CapCode
- 1
In Python, one can reverse a string by this method - (Assume the string to be x) x = x[::-1] This happens because the argument after 2 colons refers to the step and -1 will do it reverse.
29th Apr 2020, 12:16 PM
Varun Vaswani
Varun Vaswani - avatar