Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Sep 26, 2022, 2:32 AM EDT
class Program { static void Main(string[] args) { int temp; string s = Console.ReadLine(); string[] a = s.Split(' '); int k = a.Length - 1; temp = k; for (int i = k; temp >= 0; k--) { Console.Write(a[temp] + "" + ' '); --temp; } Console.ReadKey(); } }Rijwan AnsariRank #82 · 24.2K reputationPosted Sep 26, 2022, 4:53 AM EDT
Hi
Here a sample.
// C# program to reverse a string using System; public class ReverseWords { public static void Main() { string[] s = "i like this program very much".Split(' '); string ans = ""; for (int i = s.Length - 1; i >= 0; i--) { ans += s[i] + " "; } Console.Write( "Reversed String:"); Console.Write(ans.Substring(0, ans.Length - 1)); } }Sachin SinghRank #66 · 26.2K reputationPosted Sep 26, 2022, 3:07 AM EDT
follow this
https://www.c-sharpcorner.com/UploadFile/19b1bd/reverse-a-string-in-different-ways-using-C-Sharp/
Satya KarkiRank #78 · 24.6K reputationPosted Sep 26, 2022, 4:54 AM EDT
https://www.geeksforgeeks.org/c-program-to-reverse-words-in-a-given-string-2/
Vishal YelveRank #178 · 13.6K reputationPosted Sep 26, 2022, 5:41 AM EDT
Try this
public static void Main() { string line = "Hello Everyone"; Console.WriteLine("\nOriginal String: " + line); string result = ""; List wordsList = new List (); string[] words = line.Split(new [] { " " }, StringSplitOptions.None); for (int i = words.Length - 1; i >= 0; i--) { result += words[i] + " "; } wordsList.Add(result); foreach(String s in wordsList) { Console.WriteLine("\nReverse String: " + s); } }Uday DodiyaRank #239 · 10.3K reputationPosted Sep 26, 2022, 7:24 AM EDT
Hi Naresh,
Please Find Sample Programe
using System; public class ReverseWords { public static void Main() { string[] s = "i like this program very much".Split(' '); string ans = ""; for (int i = s.Length - 1; i >= 0; i--) { ans += s[i] + " "; } Console.Write( "Reversed String:"); Console.Write(ans.Substring(0, ans.Length - 1)); } }Abhishek YadavRank #217 · 11.3K reputationPosted Oct 19, 2022, 4:36 AM EDT
https://www.geeksforgeeks.org/c-program-to-reverse-words-in-a-given-string-2/
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Oct 18, 2022, 4:22 AM EDT
using System; class Demo { static void Main() { string myStr, rev; myStr = "BRAHMA"; rev =""; Console.WriteLine("String is {0}", myStr); int len; len = myStr.Length - 1; while (len >= 0) { rev = rev + myStr[len]; len--; } Console.WriteLine("Reversed String is {0}", rev); Console.ReadLine(); } } Output String is BRAHMA Reversed String is AMHARBRajeev KumarRank #1,334 · 1.3K reputationPosted Mar 14, 2023, 5:51 AM EDT
using System; using System.Linq; class Demo { static void Main() { // original string string str = "Hello World"; // reverse the string string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray()))); Console.WriteLine(res); } }